标签:des style blog http io color os ar java
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 600 Accepted Submission(s): 344
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 1005; 7 8 int fa[maxn]; 9 10 int find(int x) { 11 if(fa[x] == x) return x; 12 return fa[x] = find(fa[x]); 13 } 14 15 int main() { 16 int n, m; 17 int a, b; 18 while(EOF != scanf("%d %d",&n, &m) ) { 19 for(int i = 0; i < n; i++) fa[i] = i; 20 int cnt = 0; 21 while(m--) { 22 scanf("%d %d",&a, &b); 23 if(find(a) == find(b) ) { 24 cnt++; 25 } else { 26 fa[find(a)] = find(b); 27 } 28 } 29 printf("%d\n", cnt); 30 } 31 return 0; 32 }
标签:des style blog http io color os ar java
原文地址:http://www.cnblogs.com/zhanzhao/p/4063535.html