Ryo_Yamada @ 2020-03-28 07:23:56
闰土,参考第一篇题解的写法,结果爆零w(゚Д゚)w(
在线求助dalao
#include <iostream>
#include <cstdio>
const int N = 400005;
using namespace std;
int k, n, m, head[N], cnt, broke[N], ans[N];
int fa[N];
bool Broken[N];
struct Node {
int next, num, from;
} h[400002];
void Add(int x, int y) {
h[++cnt].from = x;
h[cnt].next = head[x];
head[x] = cnt;
h[cnt].num = y;
}
int Get(int x) {
if(fa[x] == x) return x;
return fa[x] = Get(fa[x]);
}
void merge(int x, int y) {
x = Get(x), y = Get(y);
if(x != y) fa[y] = x;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 0; i <= n; i++) fa[i] = i, head[i] = -1;
for(int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
Add(x, y);
Add(y, x);
}
cin >> k;
for(int i = 1; i <= k; i++) {
scanf("%d", &broke[i]);
Broken[broke[i]] = true;
}
int sum = n - k;
for(int i = 1; i <= 2 * m; i++) {
if(!Broken[h[i].from] && !Broken[h[i].num] && Get(h[i].from) != Get(h[i].num)) {
sum--;
merge(h[i].from, h[i].num);
}
}
ans[k + 1] = sum;
for(int i = k; i >= 1; i--) {
sum++;
Broken[broke[i]] = false;
for(int j = head[broke[i]]; j != -1; j = h[j].next) {
if(!Broken[h[j].num] && Get(broke[i]) != Get(h[j].num)) {
sum--;
merge(broke[i], h[j].num);
}
}
ans[i] = sum;
}
for(int i = 1; i <= k + 1; i++) {
printf("%d\n", ans[i]);
}
return 0;
}
by _ReClouds_ @ 2020-03-28 08:37:07
@breeze末影
你把这句话去掉看看,洛谷不一定能用
ios::sync_with_stdio(false);
by Ryo_Yamada @ 2020-03-28 08:39:54
@NOIP_First 能用的
by _ReClouds_ @ 2020-03-28 08:41:34
我用你的代码试了一下,删掉就AC了
@breeze末影
by _ReClouds_ @ 2020-03-28 08:42:17
可能有时能用,有时会有奇葩错误
by Ryo_Yamada @ 2020-03-28 08:45:40
@NOIP_First 草
我加了ios::sync_with_stdio(false);
居然还用scanf
和printf
我怕不是个zz
难怪,谢谢
by _ReClouds_ @ 2020-03-28 08:47:09
用iostream应该也行
by Ryo_Yamada @ 2020-03-28 08:48:19
@NOIP_First 嗯,本来打算用cin cout
的
by Black_Porridge @ 2020-03-28 10:00:10
好啊 有空做题没空把稿子发我