//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 0xccccccc; const ll LINF = 922337203685477580LL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} struct UnionFind { vector par; // 親を指すvector,-par[親]は木のサイズ UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり int root(int x) { // 親をたどる&データの整理 if(par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(int x, int y) { // データの結合 x = root(x); y = root(y); if(x == y) return false; if(par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y) {return root(x) == root(y);} // 所属判定 int size(int x) {return -par[root(x)];} // 木のサイズ }; const int N = 1e5+10; const int M = N<<1; //head int n, m, q; set

ab; P cd[M]; vi G[N]; UnionFind uft(N); int ans[N]; void dfs(int i, vi &u, int j = -1) { u.emplace_back(i); for(int ne:G[i]) if(ne != j) { dfs(ne, u, i); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> q; rep(i, m) { P g; cin >> g; g.first--; g.second--; ab.emplace(g); } rep(i, q) cin >> cd[i]; reverse(cd, cd+q); //cout << endl; rep(i, q) { cd[i].first--; cd[i].second--; ab.erase(cd[i]); } for(P edge:ab) { //cout << edge << endl; if(uft.unite(edge.first, edge.second)) { G[edge.first].emplace_back(edge.second); G[edge.second].emplace_back(edge.first); } } vi lst; dfs(0, lst); rep(i, lst.size()) ans[lst[i]] = -1; rep(i, q) { P edge = cd[i]; //cout << edge << endl; if(uft.same(edge.first, edge.second)) continue; if(!uft.same(edge.first, 0) and !uft.same(edge.second, 0)) { uft.unite(edge.first, edge.second); G[edge.first].emplace_back(edge.second); G[edge.second].emplace_back(edge.first); } else { lst.clear(); if(uft.same(edge.first, 0)) { dfs(edge.second, lst); } else { dfs(edge.first, lst); } //rep(i, lst.size()) cout << lst[i] << endl; uft.unite(edge.first, edge.second); rep(j, lst.size()) if(!ans[lst[j]]) ans[lst[j]] = q-i; G[edge.first].emplace_back(edge.second); G[edge.second].emplace_back(edge.first); } } for(int i = 1; i < n; i++) cout << ans[i] << '\n'; }