#include class UnionFindTree { public: UnionFindTree(int n) { rank = std::vector(n, 0); for(int i = 0; i < n; ++i) { parent.push_back(i); } } int find(int x) { if(parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]) { parent[x] = y; } else { parent[y] = x; if(rank[x] == rank[y]) ++rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } private: std::vector parent; std::vector rank; }; int main(void) { int N, M, Q; std::cin >> N >> M >> Q; UnionFindTree tree(N + 1); std::set> AB; std::vector> CD; std::set unused_nodes; std::vector answer(N + 1, 0); for(int i = 0; i < M; ++i) { int A, B; std::cin >> A >> B; AB.insert(std::make_pair(A, B)); } for(int i = 0; i < Q; ++i) { int C, D; std::cin >> C >> D; CD.push_back(std::make_pair(C, D)); AB.erase(std::make_pair(C, D)); } for(auto it = AB.begin(); it != AB.end(); ++it) { tree.unite(it->first, it->second); } for(int i = 2; i <= N; ++i) { unused_nodes.insert(i); } for(auto it = unused_nodes.begin(); it != unused_nodes.end(); ) { if(tree.same(1, *it)) { answer[*it] = -1; unused_nodes.erase(it++); } else { ++it; } } /*for(int j = 2; j <= N; ++j) { if(tree.same(1, j)) { answer[j] = -1; } }*/ for(int i = Q; 1 <= i; --i) { tree.unite(CD[i - 1].first, CD[i - 1].second); for(auto it = unused_nodes.begin(); it != unused_nodes.end(); ) { if(tree.same(1, *it)) { answer[*it] = i; unused_nodes.erase(it++); } else { ++it; } } /*for(int j = 2; j <= N; ++j) { if(tree.same(1, j)) { if(answer[j] == 0) { answer[j] = i; } } }*/ } for(int i = 2; i <= N; ++i) { std::cout << answer[i] << '\n'; } return 0; }