#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; constexpr int N_MAX = 100000; class UnionFind { public: int n; vector par, rank, size; //親, 深さ, その木の要素数 UnionFind(int n): n(n) { for(int i=0;i graph[N_MAX]; vector node_weight(N_MAX, 0), subtree_weight(N_MAX, 0); vector used(N_MAX, false); vector airport(N_MAX, -1); // uf のあるグループに存在する空港の位置 int n, m, q; ll dfs(int node, int par) { used[node] = true; for(int child: graph[node]) { if(child == par) continue; subtree_weight[node] += dfs(child, node); } subtree_weight[node] += node_weight[node]; return subtree_weight[node]; } int find_centroid(int node, int par, int root) { bool is_centroid = true; ll sum_subtree_weight = node_weight[node], biggest_child_weight = 0; int biggest_child = -1; for(int child: graph[node]) { if(child == par) continue; if(subtree_weight[child] > subtree_weight[root]/2) { is_centroid = false; } sum_subtree_weight += subtree_weight[child]; if(biggest_child_weight < subtree_weight[child]) { biggest_child_weight = subtree_weight[child]; biggest_child = child; } } if(subtree_weight[root] - sum_subtree_weight > subtree_weight[root]/2) is_centroid = false; if(is_centroid) return node; return (biggest_child != -1) ? find_centroid(biggest_child, node, root) : node; } class LowestCommonAncestor { public: int root, n, LOG_V_MAX = 30; vector depth; vector> parent; LowestCommonAncestor(int root=0, int n=N_MAX): root(root), n(n) { depth.assign(n, -1); parent.assign(n, vector(LOG_V_MAX, -1)); for(int i=0;i depth[v]) swap(u, v); int depth_diff = depth[v] - depth[u]; for(int j=0;j=0;--j) { if(parent[u][j] != parent[v][j]) { u = parent[u][j]; v = parent[v][j]; } } return parent[u][0]; } int get_dist(int u, int v) { return depth[u] + depth[v] - 2*depth[get_lca(u, v)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int u, v; cin >> n >> m >> q; UnionFind uf = UnionFind(n); for(int i=0;i> u >> v; --u; --v; graph[u].emplace_back(v); graph[v].emplace_back(u); uf.unite(u, v); } vector qs(q); for(int i=0;i> qs[i].first >> qs[i].second; --qs[i].first; --qs[i].second; if(!uf.are_same(qs[i].first, qs[i].second)) { ++node_weight[qs[i].first]; ++node_weight[qs[i].second]; } } for(int i=0;i