#include "math.h" #include #include #include #include #include #include #include #include #include #include #define ifor(i, a, b) for (int i = (a); i < (b); i++) #define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define SIZE 200005 #define UF_MAX 100005 using namespace std; typedef long double ld; typedef long long int lli; const double eps = 1e-11; int vex[4] = {1, 0, -1, 0}; int vey[4] = {0, 1, 0, -1}; lli MOD = 1000000007; int turn = 0; int ans[100005] = {}; #define UF_MAX 100005 struct UFind { int par[UF_MAX]; int rank[UF_MAX]; int count[UF_MAX]; set st[UF_MAX]; //parが全部持つ UFind(int n) { rep(i, n) { par[i] = i; rank[i] = 0; st[i].insert(i); count[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (same(x, 0) && !same(y, 0)) { for (auto s : st[y]) ans[s] = turn; } else if (!same(x, 0) && same(y, 0)) { for (auto s : st[x]) ans[s] = turn; } if (st[x].size() > st[y].size()) { for (auto s : st[y]) st[x].insert(s); par[y] = x; } else { for (auto s : st[x]) st[y].insert(s); par[x] = y; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { map> edge; int n, m, q; cin >> n >> m >> q; int a, b; UFind uf(n); rep(i, m) { cin >> a >> b; a--, b--; edge[a][b] = -1; } vector> query; rep(i, q) { cin >> a >> b; a--, b--; edge[a][b] = 1; edge[b][a] = 1; query.push_back(make_pair(a, b)); } turn = -1; for (auto s : edge) for (auto t : s.second) if (t.second == -1) uf.unite(s.first, t.first); reverse(all(query)); turn = q; rep(i, q) { uf.unite(query[i].first, query[i].second); turn--; } rep(i, n - 1) { cout << ans[i + 1] << endl; } }