// AGC002 // http://agc002.contest.atcoder.jp/submissions/828130 // #include #include #include #include #include #include using namespace std; typedef pair pii; typedef int _loop_int; #define DEBUG(x) cout<<#x<<": "<<(x)<=(_loop_int)(a);--i) // 永続配列 struct node{ int lch,rch; int val,version; }; node *nodes; int nodehead; void nodesinit(){ nodehead = 0; nodes = (node*)calloc(8000000,sizeof(node)); } int mynew(int val,int version){ nodes[nodehead].val = val; nodes[nodehead].version = version; nodes[nodehead].lch = nodes[nodehead].rch = -1; return nodehead++; } #define SIZE 262144 #define VMAX 200002 #define DEFAULT -1 struct myarray{ int now; int *rootid; myarray():now(0){ rootid = (int*)calloc(VMAX,sizeof(int)); rootid[0] = mynew(DEFAULT,0); } int getat(int v,int k){ int l=0,r=SIZE; int curid = rootid[v]; while(l+1>1; if(k>1; if(kgetat(v,x); if(r<0){ return x; }else{ return uf_root(uf,v,r); } } void uf_unite(myarray *uf,int v,int a,int b){ a = uf_root(uf,v,a); b = uf_root(uf,v,b); if(a!=b){ int sa = uf->getat(v,a); int sb = uf->getat(v,b); if(sa<=sb){ uf->setat(v,a,sa+sb); uf->setat(v,b,a); }else{ uf->setat(v,b,sa+sb); uf->setat(v,a,b); } } } int uf_same(myarray *uf,int v,int a,int b){ return uf_root(uf,v,a)==uf_root(uf,v,b); } int uf_size(myarray *uf,int v,int a){ return -uf->getat(v,uf_root(uf,v,a)); } int n,m; int q; set ori; vector del; int main(){ nodesinit(); myarray *uf = new myarray(); scanf("%d%d%d",&n,&m,&q); REP(i,m){ int a,b; scanf("%d%d",&a,&b); --a;--b; ori.insert(pii(a,b)); } REP(i,q){ int a,b; scanf("%d%d",&a,&b); --a;--b; del.push_back(pii(a,b)); ori.erase(ori.find(pii(a,b))); } for(pii P:ori){ int a=P.first, b=P.second; uf_unite(uf,0,a,b); } uf->record(); REP(i,q){ pii P = del[q-1-i]; int a=P.first, b=P.second; uf_unite(uf,i+1,a,b); uf->record(); } FOR(i,1,n){ int x=0, y=i; int low=-1,high=q+1; while(low+1>1; int rx = uf_root(uf,mid,x); int ry = uf_root(uf,mid,y); if(rx!=ry){ low = mid; }else{ high = mid; } } printf("%d\n",low==-1 ? low : q-low); } return 0; }