#include #include #include using namespace std; const int N=1e5+10,M=2e5+10; int fa[N],a[M],b[M],c[M],d[M],ans[N]; vectorv[N]; int getfa(int x) { return fa[x]==x?fa[x]:fa[x]=getfa(fa[x]); } void merge(int x,int y,int k) { if(x==y) return; if(getfa(1)==x) for(auto i:v[y]) ans[i]=k; if(getfa(1)==y) for(auto i:v[x]) ans[i]=k; if(v[x].size()g[N]; scanf("%d %d %d",&n,&m,&q); for(int i=1;i<=m;i++) scanf("%d %d",&a[i],&b[i]); for(int i=1;i<=q;i++) scanf("%d %d",&c[i],&d[i]),g[c[i]][d[i]]=true; for(int i=1;i<=n;i++) fa[i]=i,v[i].push_back(i); for(int i=1;i<=m;i++) if(!g[a[i]][b[i]]) merge(getfa(a[i]),getfa(b[i]),-1); while(q--) merge(getfa(c[q+1]),getfa(d[q+1]),q+1); for(int i=2;i<=n;i++) printf("%d\n",ans[i]); return 0; }