POJ
来源:互联网 发布:风暴英雄mac版下载 编辑:程序博客网 时间:2024/05/21 17:04
#include<algorithm>#include<cstdio>#include<cstring>#include<climits>#include<queue>#include<stack>#include<set>#include<map>#include<vector>#include<iostream>#include<string>using namespace std;int f[3 * 50000 + 1];int m, n;int getf(int x){ if(f[x] == x) return x; else return f[x] = getf(f[x]);}void unite(int x, int y){ x = getf(x); y = getf(y); if(x == y) return ; f[x] = y;}bool same(int x, int y){ if(getf(x) == getf(y)) return 1; return 0;}void init(){ for(int i = 1; i <= n*3; i++) f[i] = i;}void solve(){ int t1, t2, t3; int ans = 0; for(int i = 0; i < m; i++) { scanf("%d %d %d", &t1, &t2, &t3); if(t2 < 1 || t2 > n || t3 < 1 || t3 > n) { ans++; continue;// 如果越界直接退出 } if(t1 == 1)//当为同类的时候 { if(same(t2,t3+n) || same(t2,t3+2*n) )//判断是否符合条件 ans++; else { unite(t2,t3); unite(t2+n, t3+n); unite(t2+2*n, t3+2*n) ; } }else // 为敌人时 { if(same(t2,t3) || same(t2,t3+2*n)) // 判断是否符合条件 ans++; else { unite(t2,t3+n); unite(t2+n,t3+2*n); unite(t2+2*n, t3); } } } printf("%d\n", ans);}int main(){ scanf("%d %d", &n, &m); init(); solve(); return 0;}
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 2516 2014年中山市选拔赛 dwarf tower
- iframe嵌套界面自适应,可高度自由收缩
- HBase学习之负载均衡(balance)
- Spring MVC处理XML数据(1)
- 面试问题
- POJ
- 递归递推练习 G
- 设计模式
- 关于datagrid中field排序问题
- __attribute__((constructor)) 和 __attribute__((destructor))
- wamp集成环境安装composer和laravel5 windows下安装laravel
- 【模板】最小生成树
- 453. Minimum Moves to Equal Array Elements
- Android中assets目录和raw目录的区别和使用情况