1116: [POI2008]CLO

https://lydsy.com/JudgeOnline/problem.php?id=1116

分析:

  单独考虑每个联通块的情况。
  设这个联通块里有n个点,那么至少有n-1条边了。
  如果每个点入度都为1,那么就要求至少有n条边(其实就是基环树),大于n条边可以不选。
  所以有:如果一个联通块是可行的,必须满足存在大于等于点数条边。
  所以并查集维护加边的过程。
    1、出现了环,那么这个联通块就合法了。
    2、合并两个联通块,只要一个联通块里合法就行。(一个合法了,另一个也至少存在n-1条边,那么加入这条后,刚好满足了)。
代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; int fa[N], g[N]; int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
} int main() {
int n = read(), m = read();
for (int i = ; i <= n; ++i) fa[i] = i;
while (m --) {
int u = read(), v = read();
u = find(u), v = find(v);
if (u == v) g[u] = ;
else fa[u] = v, g[v] |= g[u];
}
for (int i = ; i <= n; ++i)
if (!g[find(i)]) return puts("NIE"), ;
puts("TAK");
return ;
}

1116: [POI2008]CLO的更多相关文章

  1. BZOJ 1116: [POI2008]CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 922  Solved: 514[Submit][Status][ ...

  2. BZOJ 1116 [POI2008]CLO(并查集)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1116 [题目大意] Byteotia城市有n个towns,m条双向roads.每条ro ...

  3. BZOJ 1116: [POI2008]CLO [连通分量]

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

  4. BZOJ 1116: [POI2008]CLO 并查集

    成立时当且仅当每个联通块都有环存在.一个连通块若有m个点,则必有多于m条有向边,可用并查集来维护. #include<cstdio> #include<iostream> #d ...

  5. BZOJ1116: [POI2008]CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 565  Solved: 303[Submit][Status] ...

  6. 【BZOJ1116】[POI2008]CLO 并查集

    [BZOJ1116][POI2008]CLO Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. ...

  7. BZOJ1116:[POI2008]CLO

    浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php? ...

  8. bzoj1116 [POI2008]CLO——并查集找环

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1116 分析性质,只要有环,那么给环定一下向就满足了条件: 环上点的其他边可以指向外面,所以两 ...

  9. bzoj1116 [POI2008]CLO 边双联通分量

    只需对每个联通块的$dfs$树检查有没有返租边即可 复杂度$O(n + m)$ #include <cstdio> #include <cstring> using names ...

随机推荐

  1. Maven经常使用命令

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/UP19910522/article/details/25985021 Maven库: http:// ...

  2. Word 2019 for mac更新喽!

    新的Word2019添加了许多的新功能,提供了新的文档处理方式,如改进的数字笔功能.焦点模式.学习工具和翻译,为用户提供了用于创建专业而优雅的高效文档工具,帮助用户节省时间,并得到优雅美观的结果,有效 ...

  3. 业务id转密文短链的一种实现思路

    业务场景: 买家通过电商app下单后,会受到一条短信,短信内容中包括改订单详情页面的h5地址连接,因为是出现在短信中,所以对连接有要求: 1.尽量短:2.安全性考虑,订单在数据库中对应的自增主键id不 ...

  4. VC++ TCP网络控制台程序

    在Windows7系统下,采用工具为VS2008,Win32控制台应用程序,编写一个基于TCP的Client/Server网络程序. 1.服务器端代码 #include <WinSock2.h& ...

  5. LeetCode刷题(数据库)---- 超过5名学生的课

    题:请列出所有超过或等于5名学生的课. 有一个courses 表 ,有: student (学生) 和 class (课程). 例如,表: +---------+------------+ | stu ...

  6. 安装Centos 7 错误解决

    dracut-initqueue[624]:Warning: Could not boot. dracut-initqueue[624]:Warning: /dev/root does not exi ...

  7. HDU 1301Jungle Roads(最小生成树 prim,输入比较特殊)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1301 Jungle Roads Time Limit: 2000/1000 MS (Java/Oth ...

  8. DataFrame查找

    一 通过索引取数据 (ix/loc/iloc) loc (根据索引名称取数据 , 适合多列) iloc (根据索引序号取数据,   适合多列) at  (和loc类似,只用于取单列, 性能更好) ia ...

  9. EF Core 2.1 Raw SQL Queries (转自MSDN)

    Entity Framework Core allows you to drop down to raw SQL queries when working with a relational data ...

  10. wordpress安装(ubuntu+nginx+php+mariadb)

    一.   环境 ubuntu12.04.4 nginx 1.6.0 mariadb 10.0 更新系统补丁 sudo apt-get update sudo apt-get dist-upgrade ...