#P13865. [SWERC 2020] Emails

[SWERC 2020] Emails

题目描述

:::align{center}

:::

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 DD:

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

输入格式

The first line of the input contains two integers NN and MM, 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 11 to NN.

The MM following lines each contain two integers, ii and jj, meaning that readers ii and jj initially have each other's email address. Note that this means that both reader ii has reader jj's address and reader jj has reader ii's address.

Limits

  • 2N1000002\leq N\leq 100\,000
  • 1M1000001\leq M\leq 100\,000

输出格式

The output should contain a single integer equal to either:

  • 1-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.
4 3
1 2
2 3
3 4
2
6 3
1 2
3 4
5 6
-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 EE for one test case and E+1E+1 for another.

Sample Explanation 1

The process proceeds as follows:

  • On day DD at 8am:
    • Reader 11 sends the address of reader 22 to reader 22.
    • Reader 22 sends the addresses of readers 11 and 33 to readers 11 and 33.
    • Reader 33 sends the addresses of readers 22 and 44 to readers 22 and 44.
    • Reader 44 sends the address of reader 33 to reader 33.
  • On day DD after the 8pm update:
    • Reader 11's address-book has been updated and contains the addresses of readers 22 and 33.
    • Reader 22's address-book has been updated and contains the addresses of readers 11, 33 and 44.
    • Reader 33's address-book has been updated and contains the addresses of readers 11, 22 and 44.
    • Reader 44's address-book has been updated and contains the addresses of readers 22 and 33.
  • On day D+1D+1 at 8am:
    • Reader 11 sends the addresses of readers 22 and 33 to readers 22 and 33.
    • Reader 22 sends the addresses of readers 11, 33 and 44 to readers 11, 33 and 44.
    • Reader 33 sends the addresses of readers 11, 22 and 44 to readers 11, 22 and 44.
    • Reader 44 sends the addresses of readers 22 and 33 to readers 22 and 33.
  • On day D+1D+1 after the 8pm update:
    • Reader 11's address-book has been updated and contains the addresses of readers 22, 33 and 44.
    • The process has converged for reader 22 since there is no update.
    • The process has converged for reader 33 since there is no update.
    • Reader 44's address-book has been updated and contains the addresses of readers 11, 22 and 33.
  • On day D+2D+2 at 8am:
    • Reader 11 sends the addresses of readers 22, 33 and 44 to readers 22, 33 and 44.
    • Reader 44 sends the addresses of readers 11, 22 and 33 to readers 11, 22 and 33.
  • On day D+2D+2 after the 8pm update:
    • The process has converged for reader 11 since there is no update.
    • The process has converged for reader 44 since there is no update. The last update takes place on day D+1D+1, after 2{\textbf 2} elapsed days. The process has converged for everyone on day D+2D+2, after 3{\textbf 3} elapsed days. The sample output contains the former value, 2{\textbf 2}. Outputting the latter value, 3{\textbf 3}, is an equally correct alternative.