#include #define int long long //#define USE_FREOPEN //#define MUL_TEST #define FILENAME "evacuate" using namespace std; int ig[100005],ans[100005]; vector gi[100005]; set > vis; int gu[100005],gv[100005],u_[100005],v_[100005]; inline int read() { int res = 0,f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { res = (res << 1) + (res << 3) + (c - 48); c = getchar(); } return res * f; } void merge(int a,int b,int k) { a = ig[a],b = ig[b]; if (a == b) return; if ((a > 1 && gi[a].size() < gi[b].size()) || b == 1) swap(a,b); for (auto u : gi[b]) { ig[u] = a; gi[a].push_back(u); } if (a == 1) for (auto u : gi[b]) ans[u] = k; gi[b].clear(); } void solve() { int n,m,q; cin >> n >> m >> q; for (int i = 1; i <= m; i++) cin >> gu[i] >> gv[i]; for (int i = 1; i <= q; i++) { int u,v; cin >> u >> v; u_[i] = u,v_[i] = v; vis.insert(make_pair(u,v)); } for (int i = 1; i <= n; i++) { ig[i] = i; gi[i].push_back(i); } for (int i = 1; i <= m; i++) if (!vis.count(make_pair(gu[i],gv[i]))) merge(gu[i],gv[i],-1); for (int i = q; i >= 1; i--) merge(u_[i],v_[i],i); for (int i = 2; i <= n; i++) printf("%lld\n",ans[i]); } signed main() { #ifdef USE_FREOPEN freopen(FILENAME ".in","r",stdin); freopen(FILENAME ".out","w",stdout); #endif int _ = 1; #ifdef MUL_TEST cin >> _; #endif while (_--) solve(); _^=_; return (0^_^0); }