시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 240 20 15 8.721%

문제

도시 N개와 도로를 연결하는 양방향 고속도로 E개로 이루어진 나라가 있다. 이 나라의 거대한 두 레스토랑 체인점은 서로 공평하게 시장을 점유하기로 결정했다. 도로의 각 중앙에는 한 레스토랑만 만들 수 있다.

두 레스토랑은 공평하게 시장을 점유하기로 결정했기 때문에, 각 도시와 연결된 도로에는 두 레스토랑이 적어도 하나씩 있어야 한다. 하지만, 도시와 연결된 도로가 하나이거나 없는 경우에는 두 체인점이 인접하는 것은 불가능하다. 이러한 경우에는 한 체인점만 이용하거나, 다른 곳으로 멀리 여행을 가면 되기 때문에 신경쓰지 않아도 된다.

위의 조건을 만족하면서 각 도로에 어떤 레스토랑 체인점을 세워야 하는지를 결정하는 프로그램을 작성하시오.

입력

첫째 줄에 도시의 수 N과 도로의 수 E가 주어진다. (1 ≤ N, E ≤ 100,000)

다음 E개 줄에는 도로의 정보 Ai와 Bi가 주어진다. 도시 Ai와 Bi를 연결하는 도로라는 뜻이며, Ai와 Bi는 같지 않다. 또, 두 도시를 연결하는 도로가 둘 이상인 경우는 없다.

출력

출력은 총 E줄을 해야 한다. i번째 줄에는 입력으로 주어진 i번째 도로에 1번 레스토랑을 놓을 것이면 1을, 2번을 놓을 것이면 2를 출력한다. 만약, 문제의 조건을 만족시키게 레스토랑을 배치할 수 없다면 0을 출력한다.

예제 입력 1

5 6
1 2
2 3
3 1
3 4
1 4
4 5

예제 출력 1

1
2
1
2
2
1
W3sicHJvYmxlbV9pZCI6IjI4ODkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI4MDhcdWMyYTRcdWQxYTBcdWI3OTEiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YjNjNFx1YzJkYyBOXHVhYzFjXHVjNjQwIFx1YjNjNFx1Yjg1Y1x1Yjk3YyBcdWM1ZjBcdWFjYjBcdWQ1NThcdWIyOTQgXHVjNTkxXHViYzI5XHVkN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mFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Contest > Croatian Open Competition in Informatics > COCI 2009/2010 > Contest #7 6번

  • 데이터를 추가한 사람: adh0463
  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: sansan709