求助,哪里错了,貌似还不止一处QAQ

P1197 [JSOI2008] 星球大战

Huanlin_ @ 2019-03-22 23:22:39

include <iostream>

include <cstdio>

include <vector>

define maxn 400001

define maxm 200001

using namespace std; int n, m, k; int fa[maxn], b[maxn], ans[maxn], list[maxn]; vector <int> e[maxm * 2]; int find(int x) { while(x != fa[x]) x = fa[x] = fa[fa[x]]; return x; } int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) fa[i] = i; for(int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); e[x].push_back(y); e[y].push_back(x); } scanf("%d", &k); ans[k] = n; for(int i = 1; i <= k; i++) { int nb; scanf("%d", &nb); list[i] = nb; b[nb] = 1; } for(int i = 1; i <= n; i++) if(!b[i]) for(int j = 0; j < e[i].size(); j++) { if(b[e[i][j]]) continue; int nx = find(i), ny = find(e[i][j]); if(nx == ny) continue; fa[ny] = nx; ans[k]--; } for(int i = k; i >= 1; i--) { int qaq = list[i]; b[qaq] = 0; ans[i - 1] = ans[i]; for(int j = 0; j < e[i].size(); j++) { if(b[e[qaq][j]]) continue; int nx = find(qaq), ny = find(e[qaq][j]); if(nx == ny) continue; fa[ny] = nx; ans[i - 1]--; } } for(int i = 0; i <= k; i++) printf("%d\n", ans[i]); return 0; }


by 花园Serena @ 2019-03-23 07:25:27

希望更丰富的展现?使用Markdown


|