Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)
D
Social Network
Codeforces
1600
原题
← CE →
翻译中…

image

翻译中…

William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.

翻译中…

The conference has $n$ participants, who are initially unfamiliar with each other. William can introduce any two people, $a$ and $b$, who were not familiar before, to each other.

翻译中…

William has $d$ conditions, $i$'th of which requires person $x_i$ to have a connection to person $y_i$. Formally, two people $x$ and $y$ have a connection if there is such a chain $p_1=x, p_2, p_3, \dots, p_k=y$ for which for all $i$ from $1$ to $k - 1$ it's true that two people with numbers $p_i$ and $p_{i + 1}$ know each other.

翻译中…

For every $i$ ($1 \le i \le d$) William wants you to calculate the maximal number of acquaintances one person can have, assuming that William satisfied all conditions from $1$ and up to and including $i$ and performed exactly $i$ introductions. The conditions are being checked after William performed $i$ introductions. The answer for each $i$ must be calculated independently. It means that when you compute an answer for $i$, you should assume that no two people have been introduced to each other yet.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $d$ ($2 \le n \le 10^3, 1 \le d \le n - 1$), the number of people, and number of conditions, respectively.

翻译中…

Each of the next $d$ lines each contain two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n, x_i \neq y_i$), the numbers of people which must have a connection according to condition $i$.

翻译中…

Output

翻译中…

Output $d$ integers. $i$th number must equal the number of acquaintances the person with the maximal possible acquaintances will have, if William performed $i$ introductions and satisfied the first $i$ conditions.

翻译中…

Note

翻译中…

The explanation for the first test case:

翻译中…

In this explanation, the circles and the numbers in them denote a person with the corresponding number. The line denotes that William introduced two connected people. The person marked with red has the most acquaintances. These are not the only correct ways to introduce people.

翻译中…

image

翻译中…

样例

Input #1
7 6
1 2
3 4
2 4
7 6
6 5
1 7
Output #1
1
1
3
3
3
6
InputCopy OutputCopy
Input #2
10 8
1 2
2 3
3 4
1 4
6 7
8 9
8 10
1 4
Output #2
1
2
3
4
5
5
6
8
InputCopy OutputCopy
题目信息
题号
1609D
时间限制
2 s
内存限制
256 MB
标签
并查集
图论
贪心
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。