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

Domjenak

설명

Mr. Malnar is organizing a banquet for 2N of his associates that are numbered
with integers 1, 2, . . . , 2N. Associates came to the banquet in pairs. Looking at
their behavior, Mr. Malnar noticed some strange rules that govern the spread of
information within this group.
First, person A is willing to share information with person B if and only if they
are friends. A pair of associates that came to the banquet together are friends.
Second, every person is willing to share information with at most one other person.
At the same time, that person must not be aware of that information.
Third, every person will try to share information where priority is given to the
person that came with them to the banquet.
In other words, if person A came with person B to the banquet and person A is
aware of some information that person B is not, person A will share that information with person B.
Because of the previous rules, person A will not share that information with anyone else and person B
will try to share it with another person that they are friends with etc.
Fourth, the group can be split into two subgroups such that if two people are friends they are not in the
same subgroup.
Mr. Malnar will tell his story to one of his associates and is interested in the maximum number of his
associates that can hear his story. If that number is \(K\), he is also interested in some sequence of associates
\(a_{1}\), \(a_{2}\), . . . , \(a_{K}\) such that if he is to tell his story to associate \(a_{1}\) then for every \(i = 1\), 2, . . . , \(K - 1\) associate
\(a_{i}\) can tell the story to associate \(a_{\)i+1\(}\).
In the process of discovering said rules Mr. Malnar determined all friendships but forgot the pairs of
associates that came to the banquet together. Fortunately, it is possible to recover this information. In
other words, there is a unique partition of associates into N pairs such that associates within the same
pair are friends.
Can you help Mr. Malnar answer his questions?

제약

Subtask 1 (24 points): \(N \le 10\)

Subtask 2 (16 points): Every associate is friends with at most two other associates.

Subtask 3 (30 points): \(N \le 2000\), \(M \le 5000\)

Subtask 4 (40 points): No additional constraints.

입력 형식

The first line contains integers \(N\) and \(M\) (\(1 \le N \le 5 \cdot 10^{5}\), \(N \le M \le 10^{6}\)), number of pairs of associates
that came to the banquet and the number of friendships.
In each of the next M lines there are two integers \(u_{i}\) and \(v_{i}\) (\(1 \le u_{i}\), \(v_{i} \le 2 \cdot N\)), labels of associates that
are friends.

출력 형식

In the first line, print a single integer K - the maximum number of associates that can hear Mr. Malnar’s
story.
In the second line, print a sequence of \(K\) integers that satisfy the constraints.

예제 1
입력
2 3
1 2
1 4
3 4
출력
4
2 1 4 3
예제 2
입력
3 5
1 2
2 3
1 4
4 5
1 6
출력
4
6 1 2 3
예제 3
입력
4 8
1 2
2 3
3 4
4 1
2 5
3 6
4 7
7 8
출력
6
6 3 4 1 2 5
설명

Clarification of the first example:
Associates that came together are: 1 and 2, 3 and 4.
Clarification of the second example:
Associates that came together are: 1 and 6, 2 and 3, 4 and 5. Longer sequences do not satisfy the
constraints. For example, sequence (3,2,1,4,5) does not satisfy the constraints even though every two
adjacent associates are friends because associate 1 can’t tell the story to person 4 after hearing it from
associate 2. This is because the associate that came with them to the banquet, namely associate 6, is still
unaware of the story (third rule).
Clarification of the third example:
Associates that came together are: 1 and 4, 2 and 5, 3 and 6, 7 and 8.

문제 정보

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

출처 COCI 2025/2026 Contest 3

평가 및 의견

Domjenak

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

Log in to rate problems.

개별 의견

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

풀이 제출

Domjenak

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