RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00150

I. Emails

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

3

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.

예제 1
입력
4 3
1 2
2 3
3 4
출력
2
예제 2
입력
6 3
1 2
3 4
5 6
출력
-1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC SWERC 2020

평가 및 의견

I. Emails

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

I. Emails

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8