/* -*- coding: utf-8 -*- * * 812.cc: No.812 Change of Class - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef vector vi; typedef queue qi; /* global variables */ vi nbrs[MAX_N]; int dists[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; nbrs[a].push_back(b); nbrs[b].push_back(a); } int q; scanf("%d", &q); while (q--) { int a; scanf("%d", &a); a--; fill(dists, dists + n, -1); dists[a] = 0; qi q; q.push(a); int c = 0, maxdist = 0; while (! q.empty()) { int u = q.front(); q.pop(); int vd = dists[u] + 1; vi &nbru = nbrs[u]; for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = *vit; if (dists[v] < 0) { c++; dists[v] = vd; q.push(v); if (maxdist < vd) maxdist = vd; } } } int d = 0, bd = 1; while (maxdist > bd) d++, bd <<= 1; printf("%d %d\n", c, d); } return 0; }