#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; typedef int Weight; struct Edge { int from, to; Weight wei; Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {} }; typedef vector Edges; typedef vector Graph; const Weight INFW = numeric_limits::max(); vector bfs(Graph &G, int start) { vector res(G.size(), -1); queue > Q; Q.push(make_pair(start, 0)); while (Q.size()) { auto p = Q.front(); Q.pop(); if (res[p.first] != -1) continue; res[p.first] = p.second; for (auto &e : G[p.first]) Q.push(make_pair(e.to, p.second + 1)); } return res; } void solve() { // Q回BFS // ある組(a, b)を考えたとき、最短経路上の真ん中にいる人が間を取り持つ int N, M; cin >> N >> M; Graph G(N); rep(i, M) { int p, q; cin >> p >> q; --p; --q; G[p].emplace_back(p, q, 1); G[q].emplace_back(q, p, 1); } int Q; cin >> Q; rep(i, Q) { int A; cin >> A; --A; vi d = bfs(G, A); int friends = -1; int day = 0; rep(j, N) { if (d[j] != -1) { friends++; if (d[j] > 1) { smax(day, d[j] / 2); } } } cout << friends << ' ' << day << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }