#include "bits/stdc++.h" using namespace std; struct unionfind { //rankのオーバーフローに注意 vector par, rank; unionfind(int n) { par.resize(n); rank.resize(n); for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 1; } } bool same(int u, int v) { return root(u) == root(v); } void unite(int u, int v) { if (same(u, v)) return; u = root(u), v = root(v); if (rank[u] > rank[v]) swap(u, v); par[u] = v; rank[v] += rank[u]; } int root(int v) { if (par[v] == v) return v; return par[v] = root(par[v]); } }; void solve() { int n, m, q; cin >> n >> m; unionfind uf(n); vector g[n]; while (m--) { int u, v; cin >> u >> v; u--, v--; uf.unite(u, v); g[u].push_back(v); g[v].push_back(u); } cin >> q; while(q--) { int a, s; cin >> a; a--; s = uf.rank[uf.root(a)] - 1; cout << s << ' '; vector d(n, -1); d[a] = 0; queue q; q.push(a); int maxi = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (int nv : g[v]) { if (d[nv] != -1) continue; d[nv] = d[v] + 1; q.push(nv); maxi = max(maxi, d[nv]); } } int l = -1, r = 20; while(l+1= maxi ? r : l) = m; } cout << r << endl; } } int main() { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }