HDU 4496
来源:互联网 发布:java内存泄露例子 编辑:程序博客网 时间:2024/06/05 14:57
思路:并查集应用,处理是倒过来处理。
#include<iostream>#include<cstdio>#include<cstring>using namespace std; int father[10005], a[100005], b[100005], block[100005]; int find(int x){ return x == father[x] ? x : father[x] = find(father[x]); }void unit(int x, int y){ int a = find(x); int b = find(y); father[a] = father[b]; return ; }int main(int argc, char const *argv[]) { int n, m; //freopen("in.c", "r", stdin); while(~scanf("%d%d", &n, &m)) { memset(block, 0, sizeof(block)); for(int i = 0; i < n; i ++) father[i] = i; for(int i = 0; i < m; i ++) scanf("%d%d", &a[i], &b[i]); for(int i = m-1; i >= 0; i --) { block[i] = n; if(find(a[i]) != find(b[i])) { n--; unit(a[i], b[i]); } } for(int i = 0;i < m; i ++) printf("%d\n", block[i]); } return 0; }
0 0
- HDU 4496
- HDU 4496
- HDU 4496 D-City
- hdu 4496 D-City
- HDU 4496 D-City
- HDU 4496 D-City
- hdu 4496 D-City
- HDU 4496 D-City
- hdu 4496 D-City
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- HDU 3549
- POJ 1273
- Codeforce A. Milking cows
- HDU 4006
- POJ 2823
- HDU 4496
- 【转】OSAL内存管理1
- Codeforces 283A
- 第二章 在窗口中绘图GDI
- HDU 3635
- Codeforce 340D
- Codeforces 237C
- Codeforces 115A
- POJ 1144