```
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 10000010
#define re register
#define FOR(i, l, r) for(re int i = l; i <= r; ++i)
using namespace std;
int n, m, c, r, t, x, y, z;
int a[maxn], b[maxn], siz[maxn], fa[maxn], son[maxn][2], fx[maxn], ss[maxn], tt[maxn];
int v[maxn], st[maxn], tag[maxn], bl[maxn], ans[maxn];
struct hz {
int a;
int b;
bool operator <(const hz &o)const {
return a < o.a || a == o.a && b < o.b;
}
}h[maxn];
int find(int x) {
if(fx[x] != x) fx[x] = find(fx[x]);
return fx[x];
}
int ifr(int x) {
return x == son[fa[x]][1];
}
int nrt(int x) {
return x == son[fa[x]][0] || x == son[fa[x]][1];
}
void push_up(int x) {
siz[x] = siz[son[x][0]]+siz[son[x][1]]+1;
}
void push_down(int x) {
if(tag[x]) {
tag[son[x][0]] ^= 1;
tag[son[x][1]] ^= 1;
swap(son[son[x][0]][0], son[son[x][0]][1]);
swap(son[son[x][1]][0], son[son[x][1]][1]);
tag[x] = 0;
}
}
void rotate(int x) {
int f = fa[x], ff = fa[f], pd1 = ifr(x), pd2 = ifr(f), t = son[x][pd1^1];
if(nrt(f)) son[ff][pd2] = x;
son[x][pd1^1] = f;
son[f][pd1] = t;
if(t) fa[t] = f;
fa[f] = x;
fa[x] = ff;
push_up(f);
push_up(x);
}
void splay(int x) {
int y = x;
st[++st[0]] = y;
while(nrt(y))
st[++st[0]] = y = fa[y];
while(st[0])
push_down(st[st[0]--]);
while(nrt(x)) {
y = fa[x];
if(nrt(y))
rotate(ifr(y) == ifr(x) ? y : x);
rotate(x);
}
push_up(x);
}
void access(int x) {
for(re int f = 0; x != 0; f = x, x = fa[f] = find(fa[x]))
splay(x), son[x][1] = f, push_up(x);
}
void makeroot(int x) {
access(x);
splay(x);
tag[x] ^= 1;
swap(son[x][0], son[x][1]);
}
void split(int x, int y) {
makeroot(x);
access(y);
splay(y);
}
int findroot(int x) {
access(x);
splay(x);
while(son[x][0])
push_down(x), x = son[x][0];
splay(x);
return x;
}
void del(int x, int y) {
if(x != 0) {
fx[x] = y;
del(son[x][0], y);
del(son[x][1], y);
}
}
void merge(int x, int y) {
if(x == y)
return;
makeroot(x);
if(findroot(y) != x) {
fa[x] = y;
return;
}
del(son[x][1], x);
son[x][1] = 0;
push_up(x);
}
int main() {
scanf("%d%d", &n ,&m);
FOR(i, 1, n) {
siz[i] = 1;
fx[i] = i;
}
FOR(i, 1, m) {
scanf("%d%d", &x, &y);
if(x > y)
swap(x, y);
h[i].a = x, h[i].b = y;
}
sort(h+1, h+m+1);
scanf("%d", &t);
int cnt = 0;
while(t != -1) {
scanf("%d%d", &x, &y);
if(x > y)
swap(x, y);
if(t == 0) {
hz hh;
hh.a = x, hh.b = y;
v[lower_bound(h+1, h+m+1, hh)-h] = 1;
}
a[++cnt] = x, b[cnt] = y, bl[cnt] = t;
scanf("%d", &t);
}
FOR(i, 1, m)
if(!v[i])
merge(find(h[i].a), find(h[i].b));
int num = 0;
for(re int i = cnt; i > 0; --i) {
if(bl[i]) {
split(find(a[i]), find(b[i]));
ans[++num] = siz[x]-1;
}
else {
merge(find(a[i]), find(b[i]));
}
}
while(num--)
printf("%d\n", ans[num]);
}
```
by Devil_Wings @ 2019-04-02 11:20:37
~~去你的萌新~~
by 闹闹、 @ 2019-04-02 11:23:35
及时打断>_<
by Devil_Wings @ 2019-04-02 11:40:08
@[一无所知](/space/show?uid=132342) 其实是现在没人。。。所以没有队形
by 闹闹、 @ 2019-04-02 11:53:12
@[Spfa](/space/show?uid=149462) 恩是这样啦
by Devil_Wings @ 2019-04-02 11:54:10
~~去你的萌新~~
by GoldenPotato137 @ 2019-04-02 12:14:03
~~去你的萌新~~
by mulberror @ 2019-04-02 12:25:52