//yukicoder@cpp17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ /* Function corner above */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ struct UnionFind { int n; vector par; vector size_; UnionFind(int n_) : n(n_), par((size_t)n_), size_((size_t)n_,1){ for(int i = 0; n > i; i++)par[i] = i; } int root(int x){ if(par[x] == x)return x; return par[x] = root(par[x]); } void unite(int a,int b){ int ra = root(a); int rb = root(b); if(ra==rb)return; if(size(ra) > size(rb)) swap(ra,rb); par[ra] = rb; size_[rb] += size_[ra]; } bool same(int a, int b){ return root(a) == root(b); } int size(int a){ return size_[root(a)]; } void debug(){ for(int i = 0; n > i; i++){ cout << size_[root(i)] << " "; } cout << endl; return; } }; vector ans(100000, 0); vector Z[100000]; void dfs(int v, int val){ ans[v] = val; for(int i = 0; Z[v].size() > i; i++){ if(ans[Z[v][i]] != val){ dfs(Z[v][i], val); } } } int main(){ int n,m,q;cin>>n>>m>>q; vector> A(m); for(int i = 0; m > i; i++){ cin>>A[i].first>>A[i].second; A[i].first--;A[i].second--; } vector> Q(q); set> bw; for(int i = 0; q > i; i++){ cin>>Q[i].first>>Q[i].second; Q[i].first--;Q[i].second--; bw.insert(Q[i]); } UnionFind uf(n); for(int i = 0; m > i; i++){ if(!bw.count(A[i])){ uf.unite(A[i].first, A[i].second); Z[A[i].first].push_back(A[i].second); Z[A[i].second].push_back(A[i].first); } } dfs(0, -1); for(int i = q-1; 0 <= i; i--){ if(uf.root(Q[i].first) != uf.root(Q[i].second)){ if(uf.root(Q[i].first) == uf.root(0)){ dfs(Q[i].second, i+1); }else if(uf.root(Q[i].second) == uf.root(0)){ dfs(Q[i].first, i+1); } uf.unite(Q[i].first, Q[i].second); Z[Q[i].first].push_back(Q[i].second); Z[Q[i].second].push_back(Q[i].first); } } for(int i = 1; n > i; i++)cout << ans[i] << endl; return 0; }