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

Naboj

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Mr. Šikić, a chemistry teacher, is playing around with \(n\) metal balls and \(m\) copper wires. He joined
together some pairs of balls with a wire so that all the balls are (directly or indirectly) linked to each
other. He wants to teach his students about electric charge so he’ll demonstrate it by charging the metal
balls in a sequence.
Mr Šikić can either charge each of the balls positively or negatively. When a ball is charged negatively,
the electrons in all the wires connected to the ball are repulsed to the other ball connected to that wire.
Conversely, if a ball is positively charged, the electrons from all the wires connected to that ball are pulled
towards it. Charging the balls has the same effect on the wires irrespective of the wire’s previous state.
At the beginning of the class all the balls hold no charge and the electrons in all the wires are still. For
every wire Mr. Šikić has a specific direction of the electron flow in mind. Help him find a sequence of ball
chargings that results in the desired electron flows.

제약

Subtask 1 (15 points): \(1 \le n \le 10\)

Subtask 2 (25 points): \(m = n - 1\)

Subtask 3 (70 points): No additional constraints.

입력 형식

The first line contains two integers \(n\) and \(m\) (\(1 \le n \le 200\,000\), \(1 \le m \le 500\,000\)) from the task statement.
The following \(m\) lines contain integers \(a_{i}\) and \(b_{i}\) (\(1 \le a_{i}\), \(b_{i} \le n\), \(a_{i}\)̸ = \(b_{i}\)) denoting that the balls \(a_{i}\) and \(b_{i}\)
are connected by a wire and the electrons in the wire should be closer to \(a@@RISE_MATH_BLOCK_0@@i\). There is at most
one wire between a pair of balls. All the balls are directly or indirectly connected by wires.

출력 형식

If it is impossible to direct the flow of electrons according to Mr. Šikić’s wishes pri\(nt -1\). Otherwise print
\(k\), the required number of ball chargings. \(k\) must be less than or equal 200 000.
In the following \(k\) lines print integers \(c@@RISE_MATH_BLOCK_0@@i\) (\(1 \le c@@RISE_MATH_BLOCK_1@@i \le 1\)), the number of the ball Mr. Šikić
should charge in \(i-th\) step and whether it should be charged positively (denoted by \(d\)\(i = 1\)) or negatively
(\(d_{i} = 0\)). If there are multiple solutions, print any one of them.

서브태스크
서브태스크점수설명

1

15점

\(1 \le n \le 10\)

2

25점

\(m = n - 1\)

3

70점

No additional constraints.

예제 1
입력
3 3
1 2
2 3
1 3
출력
3
2 1
3 0
1 1
예제 2
입력
4 3
1 2
3 2
2 4
출력
4
2 1
4 0
3 1
1 1
예제 3
입력
5 10
2 4
3 4
1 4
4 5
3 2
2 1
5 2
1 3
5 3
1 5
출력
-1
설명

Clarification of the first example:
First, we give the ball 2 a positive charge. The electrons on wires between balls 1 and 2, and balls 2 and 3
are now closer to the ball 2. The wire connecting balls 1 and 3 remains neutral.
Now we give ball 3 a negative change. The arrangement of electrons between wires 2 and 3 remains
unchanged, while the electrons on the wire between 1 and 3 are closer to the ball 1.
Finally we give ball 1 a positive charge. The wire between 1 and 3 remains unchanged, but on the wire
between balls 1 i 2 electrons are now closer to the ball 1 and the desired arrangement is achieved.

문제 정보

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

출처 COCI 2021/2022 Contest 6

평가 및 의견

Naboj

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

Log in to rate problems.

개별 의견

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

풀이 제출

Naboj

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