Emails
시간 제한3초메모리 제한512 MB
이메일 연락처 그래프가 주어질 때, 분산 방식으로 주소를 공유하는 과정이 모든 사람을 연결하는 데 며칠이 걸리는지 구하고, 불가능하면 -1을 출력한다.
문제
Ariadna's blog is filled with delicious recipes and sensible advice for a healthy and balanced lifestyle. Unsurprisingly, it has thus gathered an impressive number of readers. This reader base is now stable, and Ariadna feels that it would be useful for them to interact more and form a tighter community, one that is not solely anchored to the blog.
Ariadna knows that some of the readers are already friends or acquaintances, and therefore have each other's email addresses. She thinks that a good start for developing the community would be for everyone to have everyone else's email address, so that everyone would be able to reach out to the entire group. Since she knows her blog's readers also greatly enjoy doing things in a "decentralized" fashion, she therefore devises the following protocol, to be started on day :
- Every day at 8am, everyone sends the current list of contacts in their address book to all of the contacts in their address book.
- Every day at 8pm, everyone updates their address book, adding any new received email addresses.
If a person does not need to do any update at 8pm, then the process is said to have converged for this person, and she will no longer need to continue sending emails over the next days.
You are a skillful hacker and you have managed to get access to all of the blog readers' address books. You would like to surprise and impress Ariadna by notifying her of whether or not the process she proposes will lead to everyone getting everyone else's address. Moreover, if the process is meant to succeed, you want to give her a good estimate of how many days it would take. More precisely, if the process succeeds, you can either give her:
- the number of days (including the first day) elapsed until the last update takes place, or
- the number of days (including the first day) elapsed until the process has converged on everyone's side. Note that, according to Ariadna's definition, this is equal to +1.
입력
The first line of the input contains two integers and , corresponding to the number of readers and respectively to the number of pairs of readers that initially have each other's email address. Readers are numbered from to .
The following lines each contain two integers, and , meaning that readers and initially have each other's email address. Note that this means that both reader has reader 's address and reader has reader 's address.
출력
The output should contain a single integer equal to either:
- if the process does not lead to everyone eventually having everyone else's email address, or
- the estimated necessary number of days, otherwise. Note that this number may be equal to 0.
제한
힌트
- We assume the reader base is stable, i.e. no reader leaves and no additional reader joins throughout the process.
- We assume that everyone knows their own email address; receiving one's own address is simply ignored.
- You do no have to be "consistent" in your answers across several tests cases, meaning that you can output the value for one test case and +1 for another.