Logo
(追記) (追記ここまで)

21216번 - Emails 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB208715639.161%

문제

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 $D$:

  • 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 $E$ 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 $E$+1.

입력

The first line of the input contains two integers $N$ and $M,ドル 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 1ドル$ to $N$.

The $M$ following lines each contain two integers, $i$ and $j,ドル meaning that readers $i$ and $j$ initially have each other's email address. Note that this means that both reader $i$ has reader $j$'s address and reader $j$ has reader $i$'s address.

출력

The output should contain a single integer equal to either:

  • $-1$ 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.

제한

  • 2ドル\leq N\leq 100,000円$
  • 1ドル\leq M\leq 100,000円$

예제 입력 1

4 3
1 2
2 3
3 4

예제 출력 1

2

The process proceeds as follows:

  • On day $D$ at 8am:
    • Reader 1ドル$ sends the address of reader 2ドル$ to reader 2ドル$.
    • Reader 2ドル$ sends the addresses of readers 1ドル$ and 3ドル$ to readers 1ドル$ and 3ドル$.
    • Reader 3ドル$ sends the addresses of readers 2ドル$ and 4ドル$ to readers 2ドル$ and 4ドル$.
    • Reader 4ドル$ sends the address of reader 3ドル$ to reader 3ドル$.
  • On day $D$ after the 8pm update:
    • Reader 1ドル$'s address-book has been updated and contains the addresses of readers 2ドル$ and 3ドル$.
    • Reader 2ドル$'s address-book has been updated and contains the addresses of readers 1ドル,ドル 3ドル$ and 4ドル$.
    • Reader 3ドル$'s address-book has been updated and contains the addresses of readers 1ドル,ドル 2ドル$ and 4ドル$.
    • Reader 4ドル$'s address-book has been updated and contains the addresses of readers 2ドル$ and 3ドル$.
  • On day $D$+1 at 8am:
    • Reader 1ドル$ sends the addresses of readers 2ドル$ and 3ドル$ to readers 2ドル$ and 3ドル$.
    • Reader 2ドル$ sends the addresses of readers 1ドル,ドル 3ドル$ and 4ドル$ to readers 1ドル,ドル 3ドル$ and 4ドル$.
    • Reader 3ドル$ sends the addresses of readers 1ドル,ドル 2ドル$ and 4ドル$ to readers 1ドル,ドル 2ドル$ and 4ドル$.
    • Reader 4ドル$ sends the addresses of readers 2ドル$ and 3ドル$ to readers 2ドル$ and 3ドル$.
  • On day $D$+1 after the 8pm update:
    • Reader 1ドル$'s address-book has been updated and contains the addresses of readers 2ドル,ドル 3ドル$ and 4ドル$.
    • The process has converged for reader 2ドル$ since there is no update.
    • The process has converged for reader 3ドル$ since there is no update.
    • Reader 4ドル$'s address-book has been updated and contains the addresses of readers 1ドル,ドル 2ドル$ and 3ドル$.
  • On day $D$+2 at 8am:
    • Reader 1ドル$ sends the addresses of readers 2ドル,ドル 3ドル$ and 4ドル$ to readers 2ドル,ドル 3ドル$ and 4ドル$.
    • Reader 4ドル$ sends the addresses of readers 1ドル,ドル 2ドル$ and 3ドル$ to readers 1ドル,ドル 2ドル$ and 3ドル$.
  • On day $D$+2 after the 8pm update:
    • The process has converged for reader 1ドル$ since there is no update.
    • The process has converged for reader 4ドル$ since there is no update.

The last update takes place on day $D$+1, after 2 elapsed days. The process has converged for everyone on day $D$+2, after 3 elapsed days. The sample output contains the former value, 2. Outputting the latter value, 3, is an equally correct alternative.

예제 입력 2

6 3
1 2
3 4
5 6

예제 출력 2

-1

노트

  • 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 $E$ for one test case and $E$+1 for another.

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2020-2021 I번

  • 문제를 만든 사람: Ioana Ileana
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /