LA 3644 - X-Plosives
2015-03-26 01:19
337 查看
题目:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1645
并查集,成环的不加入ref++。
并查集,成环的不加入ref++。
#include<iostream> using namespace std; const int MAXN = 100000 + 10; int F[MAXN]; int find(int t) { if (F[t] == t) return t; return F[t] = find(F[t]); } int main() { int n, m; while (cin >> n) { for (int i = 0; i <= MAXN; i++) F[i] = i; int ref = 0; while (n!=-1) { cin >> m; n = find(n), m = find(m); if (n==m) ref++; else F = m; cin >> n; } cout << ref << endl; } }
相关文章推荐
- LA - 3644 - X-Plosives
- [LA] 3644 - X-Plosives [并查集]
- LA 3644 X-Plosives && LA 3027 Corporative Network (并查集入门)
- 并查集(图论) LA 3644 X-Plosives
- LA 3644 X-Plosives (并查集)
- LA 3644 X-Plosives
- LA 3644 X-Plosives
- LA -3644 X-Plosives -并查集
- LA 3644 X-Plosives
- (DS 《算法竞赛入门经典》)LA 3644 X-Plosives(并查集)
- LA 3644 X-Plosives 易爆物
- X-Plosives问题, LA 3644, 并查集算法
- LA 3644 - X-Plosives,并查集
- LA 3644 X-Plosives (Europe - Southwestern - 2006/2007)
- LA 3644 X-Plosives (Europe - Southwestern - 2006/2007)
- X-Plosives(LA 3644)并查集
- LA 3644 - X-Plosives ( 也即UVA 1160)
- LA 3644 X-Plosives (Europe - Southwestern - 2006/2007)
- LA 3644 X-Plosives
- LA 3644 - X-Plosives ( 也即UVA 1160)