#include using namespace std; // not... struct UnionFind { vector data; void init(int n) { data.assign(n, -1); } bool unionSet(int x, int y) { x = root(x); y = root(y); if(x != y) { if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main() { int N; int M; int Q; while(~scanf("%d%d%d", &N, &M, &Q)) { set > edges; for(int i=0;i B)swap(A, B); edges.insert(make_pair(A, B)); } vector > queries(Q); for(int i=0;i B)swap(A, B); edges.erase(make_pair(A, B)); queries[i] = make_pair(A, B); } UnionFind uf; uf.init(N); for(auto e : edges) uf.unionSet(e.first, e.second); vector ans(N, 0); for(int i=0;i> as(N); for(int i=0;i= 0; -- i) { auto e = queries[i]; int x = e.first, y = e.second; x = uf.root(x), y = uf.root(y); if(x == y) continue; if(uf.findSet(0, y)) swap(x, y); vector &v = as[x], &w = as[y]; if(uf.findSet(0, x)) { for(int j : w) ans[j] = i + 1; } if(v.size() < w.size()) v.swap(w); v.insert(v.end(), w.begin(), w.end()); w.clear(); uf.unionSet(x, y); as[uf.root(x)].swap(v); } for(int i = 1; i < N; ++ i) printf("%d\n", ans[i]); } return 0; }