#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i P; struct edge { LL to, cost; }; const LL inf = 1123456789; std::vectordist; std::vector>G; void dijkstra(LL s) { std::priority_queue, std::greater

>que; std::fill(dist.begin(), dist.end(), inf); dist[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); LL v = p.second; if (dist[v] < p.first) continue; rep(i, G[v].size()) { edge e = G[v][i]; if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(P(dist[e.to], e.to)); } } } } int main() { LL N, M, Q; in >> N >> M; std::vectorp(M), q(M); rep(i, M) in >> p[i] >> q[i]; in >> Q; std::vectorA(Q); rep(i, Q) in >> A[i]; G.resize(N + 1); rep(i, M) { G[p[i]].push_back({ q[i],1 }); G[q[i]].push_back({ p[i],1 }); } rep(i, Q) { dist.clear(); dist.resize(N + 1); dijkstra(A[i]); LL ans1 = 0, ans2 = 0; for (LL j = 1; j <= N; ++j) { if (A[i] == j) continue; if (dist[j] < inf) { ++ans1; if (dist[j] > 1) { LL temp = dist[j] - 1, res = 0; while (temp > 0) { temp /= 2; ++res; } ans2 = std::max(ans2, res); } } } out << ans1 << " " << ans2 << std::endl; } }