#include #include #include #include #include #include #include #include #include class quick_find { std::vector> groups; std::vector index; public: quick_find(size_t n): index(n) { std::iota(index.begin(), index.end(), 0); for (size_t i = 0; i < n; ++i) groups.emplace_back(1, i); } bool unite(size_t u, size_t v) { if (index[u] == index[v]) return false; if (groups[index[u]].size() > groups[index[v]].size()) std::swap(u, v); size_t pi = index[u]; for (size_t i: groups[index[u]]) { index[i] = index[v]; groups[index[v]].push_back(i); } groups[pi].clear(); return true; } const std::vector& components(size_t v) const { return groups[index[v]]; } bool connected(size_t u, size_t v) const { return index[u] == index[v]; } }; int main() { size_t N, M, Q; scanf("%zu %zu %zu", &N, &M, &Q); using edge = std::pair; std::vector ab(M); for (auto& p: ab) { scanf("%zu %zu", &p.first, &p.second); --p.first; --p.second; } std::vector cd(Q); std::set es; for (auto& p: cd) { scanf("%zu %zu", &p.first, &p.second); --p.first; --p.second; es.emplace(p.first, p.second); } quick_find qf(N); for (const auto& p: ab) { size_t a, b; std::tie(a, b) = p; if (es.count({a, b})) continue; qf.unite(a, b); } std::vector res(N, 0); for (size_t u: qf.components(0)) res[u] = -1; for (size_t i = Q; i--;) { size_t c, d; std::tie(c, d) = cd[i]; if (qf.connected(c, d)) continue; size_t u = 0; if (qf.connected(0, c)) { u = d; } else if (qf.connected(0, d)) { u = c; } if (u != 0) { const auto& cmp = qf.components(u); for (size_t v: cmp) res[v] = i+1; } qf.unite(c, d); } res.erase(res.begin()); for (auto ri: res) printf("%d\n", ri); }