UVA 1160 X-Plosives
2013-03-27 20:19
357 查看
大意略。
#include <iostream> #include <fstream> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <vector> #include <algorithm> #include <stack> using namespace std; const int maxn = 100010; int pa[maxn]; void init() { for(int i = 0; i < 100001; i++) pa[i] = i; } int find(int x) { return x == pa[x] ? x : pa[x] = find(pa[x]); } int main() { int x, y; while(~scanf("%d", &x)) { init(); int ans = 0; while(x != -1) { scanf("%d", &y); x = find(x), y = find(y); if(x != y) pa[x] = y; else ans++; scanf("%d", &x); } printf("%d\n", ans); } return 0; }
相关文章推荐
- UVA 1160 X-Plosives
- uva 1160 x plosives
- UVA 1160 X-Plosives(并查集)
- UVa 1160 X-Plosives (并查集)
- 并查集uva1160 - X-Plosives
- UVa 1160 X-Plosives
- uva 1160 - X-Plosives
- UVA 1160 - X-Plosives(并查集)
- LA 3644 - X-Plosives ( 也即UVA 1160)
- UVA 1160 X-Plosives
- Uva 1160 X-Plosives ——并查集
- uva 1160 X-Plosives (并查集)
- UVA 1160 X-Plosives
- LA 3644 - X-Plosives ( 也即UVA 1160)
- uva 1160 - X-Plosives
- UVa 1160 - X-Plosives
- Uva-1160-X-Plosives
- UVA 1160 X-Plosives【并查集】
- UVA 1160 X-Plosives
- uva 1160 - X-Plosives(并查集)