标签:cas pac log ace pre end break 数字 数据
10 9 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 10 4 2 3 4 5 4 8 5 8 0 0
Case 1: 1 Case 2: 7
并查集
#include<iostream> #include<cstring> using namespace std; int father[100005]; int find(int x) { if(-1==father[x])return x; else return find(father[x]); } int main() { int n,m; int tmp=0; while(11101001) { cin>>n>>m; memset(father,-1,sizeof father); if(n==0&&m==0)break; int a,b; for(int i=1;i<=m;i++) { cin>>a>>b; int fa=find(a),fb=find(b); if(fa!=fb)father[fa]=fb,n--; } cout<<"Case "<<++tmp<<": "<<n<<endl; } return 0; }
标签:cas pac log ace pre end break 数字 数据
原文地址:http://www.cnblogs.com/sssy/p/7214727.html