D - The Suspects
来源:互联网 发布:java笔试题及答案2017 编辑:程序博客网 时间:2024/05/20 23:02
代码:
#include<iostream>#include<stdio.h>using namespace std;int re[50010];int init(int &n){ for(int i=0; i<n+1; i++) re[i]=i; return 0;}int find(int x){ if(re[x]==x) return x; re[x]=find(re[x]); return re[x];}int main(){ int n,m,p,q; int i,j,k=0,ans; while(scanf("%d%d",&n,&m),(m&&n)) { k++; ans=0; init(n); for(i=0; i<m; i++) { scanf("%d%d",&p,&q); p=find(p); q=find(q); if(p!=q) re[p]=q;//re[q]=p; } for(i=1; i<=n; i++) if(re[i]==i) ans++; printf("Case %d: %d\n",k,ans); } return 0;}
0 0
- D - The Suspects
- D - The Suspects
- D - The Suspects
- D - The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- 敏捷开发实践(1)-故事工作量估算导致的问题
- C语言指针数组和数组指针
- 如何删除”我的电脑“中的百度云管家图标
- python 信号处理句柄第二个参数的作用
- qsub提交到PBS的脚本中不能使用 &(后台运行命令)?!
- D - The Suspects
- 如何显示文件后缀名(来源 百度)
- 分类器是如何做检测的?——CascadeClassifier中的detectMultiScale函数解读
- Android Camera Framework
- 空基类优化
- QT4升级到Qt5各种问题
- 畅通工程续
- 字符串窗口覆盖 Minimum Window Substring
- 【git】error: src refspec master does not match any.