Restoran
의견: 0
In Croatia there are \(N\) cities connected by \(E\) two-way roads. Two large food chains have recently reached an agreement on market sharing. In the middle of each road, exactly one chain will be given rights to build a restaurant.
To ensure the market is shared fairly, each city must have at least one restaurant from each chain on the roads connected to that city. However, there are cities with only one road, or no roads at all, and for them it is impossible to have both chains. Such cities are doomed to visit one chain, or travel a bit further.
Write a program that will determine for each road the chain that should build there so that these requirements are met.
This taks has test cases grouped into test runs. Each test run consists of one
or more test cases. In order to score points for the test run, all test cases in
the run must be solved correctly.
You do not need to worry about test runs during input and output. The
system does that for you. Follow the format described in INP\(UT/OU\)TPUT to
the letter!
Test runs worth 60% have \(N \le 1000\), \(E \le 5000\).
SAMPLE TEST CASES
Input:
5 6
1 2
2 3
3 1
3 4
1 4
4 5
Input:
7 7
1 2
2 3
3 1
4 5
5 6
6 7
7 4
Input:
77777 4
1 2
1 3
1 4
1 5
Output:
1
2
1
2
2
1
Output:
0
Output:
1
2
2
2
The first line of input contains two integers \(N\) and \(E\) (\(1 \le N, E \le 100\,000\)), the number of cities and the number of roads.
The next \(E\) lines contain two integers each. Each line describes one road. Integers \(A_i\) and \(B_i\) (\(1 \le A_i, B_i \le N\); \(A_i \ne B_i\)) denote a road connecting cities \(A_i\) and \(B_i\).
There will never be two or more roads connecting the same cities.
If there is no way to fairly assign the roads, the first and only line of output should contain 0.
Otherwise output exactly \(E\) lines, one for each road, in the same order as they were given in the input. The \(i\)-th line should contain 1 if the first chain has the right to build on this road, or 2 if the second one does.
Note: if the solution is not unique, you may output any valid one.
Scoring: This task has test cases grouped into test runs. In order to score points for a test run, all test cases in the run must be solved correctly. Test runs worth \(60\%\) of points have \(N \le 1000\), \(E \le 5000\).
| 서브태스크 | 점수 | 설명 |
|---|---|---|
Test 1 | 5점 | None |
Test 2 | 5점 | None |
Test 3 | 5점 | None |
Test 4 | 5점 | None |
Test 5 | 5점 | None |
Test 6 | 5점 | None |
Test 7 | 5점 | None |
Test 8 | 5점 | None |
Test 9 | 5점 | None |
Test 10 | 5점 | None |
Test 11 | 5점 | None |
Test 12 | 5점 | None |
Test 13 | 5점 | None |
Test 14 | 5점 | None |
Test 15 | 5점 | None |
Test 16 | 5점 | None |
Test 17 | 5점 | None |
Test 18 | 5점 | None |
Test 19 | 5점 | None |
Test 20 | 5점 | None |
5 6
1 2
2 3
3 1
3 4
1 4
4 51
2
1
2
2
17 7
1 2
2 3
3 1
4 5
5 6
6 7
7 4077777 4
1 2
1 3
1 4
1 51
2
2
2평가 및 의견
Restoran
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Restoran