思路为离线下来依次加边,如果这个点没有被删就一开始连上去,然后并查集维护连通性,但是 WA 了两个点,求查错
/*
Author: TheSky233
Windows 11 Creation. All rights reserved.
*/
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
#define Multicase() for(int T = read() ; T ; T--)
#define lowbit(x) (x & (-x))
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
#define l(p) tree[p].l
#define r(p) tree[p].r
#define sum(p) tree[p].sum
#define tag(p) tree[p].tag
#define F(i,a,b) for(int i=(a) ;i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i< (b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define endl '\n'
#define umap unordered_map
#define ENDL putchar('\n')
#define forGraph(u) for(int i=head[u];i;i=G[i].next)
#define _file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
const int N=5e6+5;
const int M=5e6+5;
const int MN=1e3+5;
const int iinf=INT_MAX;
const double eps=1e-9;
const double pi=acos(-1);
const long long linf=LLONG_MAX;
const long long mod=1000000007,mod2=998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<string,int> msi;
inline int read(){int x(0), f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} return f?-x:x;}
template <typename T> void read(T &x){x=0; T f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} x=f?-x:x;}
template <typename T,typename ...Arg>void read(T& x,Arg& ...arg){read(x);read(arg...);}
template <typename T> inline void write(T x){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot);}
template <typename T> void write(T x,char c){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot); putchar(c);}
void judge(bool x){printf(x?"YES\n":"NO\n");}
void Solve();
struct Edges{
int from,to;
}Edge[M<<1];
int brk[M<<1];
int n,m,e,q,k,p;
int a[N],b[N],f[N];
vector<int> v;
signed main(){
// Multicase()
Solve();
}
int fa[N],siz[N];
int find(int x){if(x!=fa[x]) return fa[x]=find(fa[x]); return fa[x];}
void merge(int x,int y){
int fx=find(x),fy=find(y);
fa[min(fx,fy)]=max(fx,fy);
siz[max(fx,fy)]+=siz[min(fx,fy)];
}
bool iselec(int x){
return x>n;
}
bool notelec(int x){
return x<=n;
}
unordered_map<int,bool> mp;
int ans;
void Solve(){
mp.clear();
read(n,m,e);
F(i,1,n+m) fa[i]=i,siz[i]=1;
F(i,1,e){
int u,v;
read(u,v);
Edge[i]={u,v};
}
read(q);
F(i,1,q) read(brk[i]),mp[brk[i]]=1;
F(i,1,e) if(!mp[i]) merge(Edge[i].from,Edge[i].to);
F(i,1,n) if(iselec(find(i))) ans++;
dF(i,q,1){
f[i]=ans;
int u=Edge[brk[i]].from,v=Edge[brk[i]].to;
int rx=find(u),ry=find(v);
if(iselec(rx) && notelec(ry)) ans+=siz[ry];
else if(iselec(ry) && notelec(rx)) ans+=siz[rx];
merge(rx,ry);
}
F(i,1,q) write(f[i],'\n');
}