// yukicoder: No.812 Change of Class // 2019.7.13 bal4u #include #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(int n) { // 非負整数の表示(出力) int i; char b[20]; if (!n) pc('0'); else { i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } } void outs(char *s) { while (*s) pc(*s++); } #define QMAX 5000000 #define MAX 100005 typedef struct { int a, s; } Q; Q que[QMAX+3]; int top, end; int *to[MAX], hi[MAX]; int N; char vis[MAX]; int main() { int i, p, q, s, M, ma; int *memo, sz; N = in(), M = in(); memo = malloc(sizeof(int)*M*2); sz = 0; while (M--) { p = in()-1, q = in()-1; memo[sz++] = p, memo[sz++] = q; hi[p]++, hi[q]++; } i = N; while (i--) if (hi[i]) to[i] = malloc(sizeof(int)*hi[i]); memset(hi, 0, sizeof(int)*N); i = 0; while (i < sz) { p = memo[i++], q = memo[i++]; to[p][hi[p]++] = q, to[q][hi[q]++] = p; } // free(memo); M = in(); while (M--) { p = in()-1; if (hi[p] == 0) { outs("0 0\n"); continue; } if (hi[p] == 1 && hi[to[p][0]] == 1) { outs("1 0\n"); continue; } que[0].a = p, que[0].s = 0, top = 0, end = 1, sz = -1, ma = 0; memset(vis, 0, N); while (top != end) { p = que[top].a, s = que[top++].s; if (vis[p]) continue; vis[p] = 1, sz++; i = hi[p]; while (i--) { q = to[p][i]; if (!vis[q]) { que[end].a = q, que[end++].s = s+1; if (s == ma) ma++; } } } ma--, i = 0; while (ma) i++, ma >>= 1; out(sz), pc(' '), out(i), pc('\n'); } return 0; }