#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} const int MAX_N = 200100; int par[MAX_N]; // 親 int rank_[MAX_N]; // 木の深さ int cnt_[MAX_N]; // 属する頂点の個数(親のみ正しい) // n要素で初期化 void UFinit(){ for(int i=0;i> n >> m >> q; int a[m], b[m], c[q], d[q]; rep(i,m){ cin >> a[i] >> b[i]; a[i]--; b[i]--; } rep(i,q){ cin >> c[i] >> d[i]; c[i]--; d[i]--; } map mp; rep(i,m)mp[P(a[i],b[i])] = q + 1; rep(i,q)mp[P(c[i],d[i])] = i + 1; vector

G[q+2]; for(auto x : mp) G[x.second].push_back(x.first); int l[n] = {}, r[n]; rep(i,n){ r[i] = q+1; } rep(_,30){ vector v[q+2]; int cnt = 0; rep(i,n){ if(l[i]==r[i])continue; int mid = (l[i]+r[i]) / 2 + 1; v[mid].push_back(i); cnt++; } if(cnt==0)break; UFinit(); int ite = 0; drep(i,q+2){ rep(j,G[i].size()){ unite(G[i][j].first, G[i][j].second); } rep(j,v[i].size()){ if(same(v[i][j], 0)){ l[v[i][j]] = i; }else{ r[v[i][j]] = i-1; } } } } srep(i,1,n){ if(l[i]==0){ cout << 0 << endl; }else if(l[i]==q+1){ cout << -1 << endl; }else{ cout << l[i] << endl; } } return 0; }