問題一覧 > 通常問題

No.812 Change of Class

レベル : / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 177
作問者 : hamuhei4869 / テスター : koba-e964
お気に入りにしたユーザー ProblemId : 2850 / 自分の提出
問題文最終更新日: 2019-03-30 18:29:23
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 210 (順位表) の他の問題:

Problem Statement

Hamuhei's new class has $N$ members, numbered $1 \sim N$. The existing friendships in this class are represented by the following $M$ pieces of information.


  • Person $p_i$ and person $q_i$ are friends. $(1 \leqq i \leqq M)$

In this class, each time a day passes, the friendships change as follows.

  • Consider a pair of people $(a, b)$ who are not yet friends. If there exists a person who is friends with both $a$ and $b$, then $a$ and $b$ become friends at the end of that day.
  • A friendship is never dissolved.

$Q$ people's names will be called.
Let $A_i$ be the person whose name is called $i$-th.
For each $i(1 \leqq i \leqq Q)$, answer the maximum number of people that person $A_i$ can become friends with. Also answer on which day that number can be achieved, where the first day is counted as day 0.

Input

$N\ M$
$p_1 q_1$
.
.
.
$p_M q_M$
$Q$
$A_1$
.
.
.
$A_Q$

$1 \leqq N \leqq 10^5$
$0 \leqq M \leqq \min((N * (N-1))/2, 10^5)$

For $i(1 \leqq i \leqq M)$
$1 \leqq p_i < q_i \leqq N$

If $i \neq j$, then
$(p_i, q_i) \neq (p_j, q_j)$

$1 \leqq Q \leqq 30$
$1 \leqq A_i \leqq N (1 \leqq i \leqq Q)$

Output

Output the answers in $Q$ lines. On the $i$-th line, output the answer for the $i$-th person $(A_i)$.
Specifically, on the $i$-th line,
output, separated by a space, the maximum number of people that the $i$-th person $A_i$ can become friends with, and the day on which that number can be achieved, where the first day is counted as day 0.

Sample

Sample 1
Input
2 1
1 2
2
1
2
Output
1 0
1 0

In the existing state, 1 and 2 are friends, and neither of them can gain any more friends.

Sample 2
Input
5 3
1 2
2 3
3 4
5
1
2
3
4
5
Output
3 2
3 1
3 1
3 2
0 0

Note that there may be a person who cannot become friends with anyone.

Sample 3
Input
18 13
1 2
3 4
4 5
6 7
7 8
8 9
9 10
11 12
12 13
13 14
14 15
15 16
16 17
4
1
3
6
11
Output
1 0
2 1
4 2
6 3

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。