LA 3644
来源:互联网 发布:知乎每日精选 编辑:程序博客网 时间:2024/04/28 18:27
题目:http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=12648
并查集得到运用,检查X,Y是否在同一个集合中,如果是++cnt,反之将Y存入集合。
#include<cstdio>using namespace std;const int maxn = 100000+10;int f[maxn];int find(int x){ if(f[x]!=x) return f[x]=find(f[x]); return x;}int main(){ int x,y; while( scanf("%d",&x)!=EOF ){ for(int i=0;i<maxn;i++) f[i]=i; int ans=0; while(x!=-1){ scanf("%d",&y); int fx=find(x); int fy=find(y); if(fx==fy) ans++; else f[fx]=fy; scanf("%d",&x); } printf("%d\n",ans); } return 0;}
- LA 3644
- LA 3644
- LA 3644
- 易炸物(LA 3644)
- LA - 3644 - X-Plosives
- LA 3644 X-Plosives
- LA 3644 X-Plosives
- LA 3644 X-Plosives
- LA 3644 X-PIosives
- LA 3644 X-Plosives
- LA 3644 - X-Plosives
- LA 3644 X-Plosives
- LA 3644 X-Plosives
- la la la, la la la
- LA 3644 并查集
- 并查集 LA 3644
- LA 3644 并查集
- 并查集 LA 3644
- 【phpcms-v9】phpcms-v9中复制采集节点功能(扩展:专题碎片的复制)
- 6高次方数的尾数-求13的13次方的最后三位数
- linux网络编程异步IO模型之—select模型 .
- 在MyEclipse中使用版本控制系统CVS
- WINCE GPIO S3C2440
- LA 3644
- [C++][Thread] 转:线程池原理及创建(C++实现) .
- 两种方法利用Java生成唯一ID,取当前时间与字母随机组合,并发少的情况足以胜任
- ADO 教程 (VC++)
- 日常NSDate使用整理
- Porting LTP to Android
- C++ - 网络编程模型 - Linux EPOLL .
- Sequel中文文档-模型-关联基础
- vector去重 nyoj 8 一种排序