#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; class UnionFind { public: vector Parent; UnionFind(int N) { Parent = vector(N, -1); } int root(int A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } long long size(int A) { return -(long long)Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) { swap(A, B); } Parent[A] += Parent[B]; Parent[B] = A; return true; } }; vector> g; void dfs(int cur, vector& res, int idx) { if (res[cur] != 0) return; res[cur] = idx; for (auto next : g[cur]) { dfs(next, res, idx); } } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, m, Q; scanf("%d %d %d", &n, &m, &Q); g.resize(n); vector> vp(m); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; if (u > v) swap(u, v); vp[i] = { u,v }; } sort(vp.begin(), vp.end()); vector used(m, false); vector> q(Q); for (int i = 0; i < Q; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; if (u > v) swap(u, v); q[i] = make_pair(u, v); int idx = lower_bound(vp.begin(), vp.end(), q[i]) - vp.begin(); used[idx] = true; } UnionFind uni(n); for (int i = 0; i < m; i++) { if (!used[i]) { uni.connect(vp[i].first, vp[i].second); g[vp[i].first].push_back(vp[i].second); g[vp[i].second].push_back(vp[i].first); } } vector res(n); for (int i = 1; i < n; i++) { if (uni.root(0) == uni.root(i)) { res[i] = -1; } } for (int i = Q - 1; i >= 0; i--) { if (uni.root(q[i].first) == uni.root(q[i].second)) continue; bool f = (uni.root(0) == uni.root(q[i].first)); bool s = (uni.root(0) == uni.root(q[i].second)); if (!f and s) { dfs(q[i].first, res, i + 1); } else if (f and !s) { dfs(q[i].second, res, i + 1); } uni.connect(q[i].first, q[i].second); g[q[i].first].push_back(q[i].second); g[q[i].second].push_back(q[i].first); } for (int i = 1; i < n; i++) { printf("%d\n",res[i]); } return 0; }