【并查集判环】hdu 2120 Ice_cream's world I
2014-04-05 12:04
423 查看
#include <stdio.h> #include <map> #include <math.h> #include <algorithm> #include <string> #include <string.h> #include <iostream> #define mm(a) memset(a, 0, sizeof(a)) using namespace std; int father[1111]; int findd(int x) { if(x != father[x]) father[x] = findd(father[x]); return father[x]; } int main() { int n, m; while(scanf("%d%d", &n, &m) != EOF) { for(int i = 0; i < n; i ++) father[i] = i; int cnt = 0; while(m--) { int a, b; scanf("%d%d", &a, &b); a = findd(a); b = findd(b); if(a != b) father[a] = b; else if(a == b) cnt ++; } printf("%d\n", cnt); } return 0; }
相关文章推荐
- Ice_cream's world I hdu 2120 并查集判断环
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- 【HDU】-2120-Ice_cream's world I(并查集,环)
- hdu杭电2120 Ice_cream's world I【并查集】
- HDU 2120 Ice_cream's world I(并查集,环的个数,冰激凌王国有什么?)
- HDU-2120-Ice_cream's world I【并查集】
- HDU 2120 Ice_cream's world I(并查集)
- hdu 2120 Ice_cream's world I(判断是否有环,简单的并查集)
- hdu 2120 Ice_cream's world I 并查集
- hdu 2120 Ice_cream's world I (简单并查集 + 判环)
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- HDU 2120 Ice_cream's world I 基础并查集★
- HDU 2120 Ice_cream's world I 并查集
- hdu 2120 Ice_cream's world I
- hdoj 2120 Ice_cream's world I 【并查集判断成环数】
- HDOJ题目2120 Ice_cream's world I(并查集)
- 【HDU 2120 Ice_cream's world I】
- HDU 2120 Ice_cream's world I
- HDU 2120-Ice_cream's world I
- HDOJ 2120 Ice_cream's world I(并查集)