传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1116

题目大意:Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度

题解:并查集

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cstdio>
 5 #include<cmath>
 6 #define maxn 100005
 7 using namespace std;
 8 int n,m;
 9 int fa[maxn];
10 bool mark[maxn];
11 int read()
12 {
13     int x=0; char ch; bool bo=0;
14     while (ch=getchar(),ch<'0'||ch>'9') if (ch=='-') bo=1;
15     while (x=x*10+ch-'0',ch=getchar(),ch>='0'&&ch<='9') ;
16     if (bo) return -x; return x;
17 }
18 int find(int x)
19 {
20     if (fa[x]!=x) fa[x]=find(fa[x]);
21     return fa[x];
22 }
23 int main()
24 {
25     n=read(); m=read();
26     for (int i=1; i<=n; i++) fa[i]=i;
27     for (int i=1; i<=m; i++)
28     {
29         int u=read(),v=read();
30         int q=find(u),p=find(v);
31         if (q!=p)
32         {
33             fa[q]=p; mark[p]=mark[p] | mark[q];
34         }
35         else
36         mark[q]=1;
37     }
38     for (int i=1; i<=n; i++)
39     if (!mark[find(i)])
40     {
41         printf("NIE");
42         return 0;
43     }
44     printf("TAK"); return 0;
45 }

View Code

转载于:https://www.cnblogs.com/HQHQ/p/5578220.html

bzoj1116: [POI2008]CLO相关推荐

  1. bzoj1116[POI2008]CLO*

    bzoj1116[POI2008]CLO 题意: n点m边双向图,问能否将一些边变成单向使得每个点只有一个入度.n≤100000,m≤200000. 题解: 结论:当图中每个点都与至少一个环相连时满足 ...

  2. bzoj1116 [POI2008]CLO

    题目链接 画画图发现如果某一个连通块中没有环那么就不可能存在方案 所以直接并查集维护一个连通块中有没有环 1 #include<algorithm> 2 #include<iostr ...

  3. BZOJ1116:[POI2008]CLO(并查集)

    Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个t ...

  4. bzoj 1116: [POI2008]CLO(并查集)

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1180  Solved: 649 [Submit][Statu ...

  5. 1116: [POI2008]CLO

    1116: [POI2008]CLO https://lydsy.com/JudgeOnline/problem.php?id=1116 分析: 单独考虑每个联通块的情况. 设这个联通块里有n个点,那 ...

  6. [POI2008]CLO

    题面 <center>2026: [POI2008]CLO<center> <center>时间限制:10秒 内存限制:162MB<center> 题目 ...

  7. BZOJ 1116 POI2008 CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1152  Solved: 635 [Submit][Statu ...

  8. 【bzoj1116】 [POI2008]CLO

    Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个t ...

  9. 【BZOJ1116】[POI2008]CLO【BFS】

    [题目链接] 同[这个题] /* Pigonometry */ #include <cstdio> #include <algorithm>using namespace st ...

最新文章

  1. 传道、授业、解惑:俞士纶院长参加数据科学研究院第五届“院长接待日”
  2. linux获取url中文内容_Chrome OS 似乎将在Linux 的方向上更进一步
  3. DIV+CSS如何设置字体间距
  4. codeforces271D
  5. 【项目实战课】基于ncnn框架与KL散度的8bit对称模型量化与推理实战
  6. 计算机网络实验(华为eNSP模拟器)——第五章 单臂路由
  7. [PAT乙级]1047 编程团体赛
  8. 【Linux学习】强大的文本分析工具AWK
  9. 『转』度百死去飞秋一个BUG引发的血案
  10. 利用NABCD模型进行竞争性需求分析
  11. 【Inpho精品教程】任务二:Inpho创建工程(创建项目、新建相机参数、导入照片、导入POS、生成航条、保存项目)
  12. 什么是GPU服务器?如何正确选择?
  13. 04-SNAP处理Sentinel-2 L2A级数据(二)
  14. CSS实战样式:文字两侧加居中横线
  15. Notion为什么能让我放弃手账
  16. 做国内最好的考勤软件,领航软件被评为2007中国软件创新100家典型企业
  17. Android无限滑动控件实现
  18. [Python] Python数值取整
  19. PostgreSQL数据库导入EXCEL数据表
  20. Johnson-Trotter(生成排列算法)

热门文章

  1. java 服务器读取客户端文件,java 服务器读取客户端文件
  2. html生成自定义表格,自定义js的表格插件
  3. mysql中distinct关键字,MySQL关键字Distinct的详细介绍
  4. java三板斧_Java 枚举使用三板斧
  5. python indexerror怎么办_Python IndexError:使用列表作为可迭代对象时...
  6. 快速傅里叶变换(FFT)——按频率抽取DIF的基
  7. db,dbms,dba_DBMS中的数据库管理员(DBA)
  8. 软件开发模型和软件过程模型_什么是软件和软件过程?
  9. 数字图像的大小、所需比特数(二维)
  10. java split 坑_java String split 踩坑记