| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 (추가 시간 없음) | 1024 MB | 19 | 11 | 6 | 46.154% |
Unfortunately, this year, you somehow managed to make your math teacher at school really angry with you. He wants to take his revenge but without raising any suspicion. After some thought, he comes up with a plan: he will hand you a list of very boring math exercises that you'll have to solve during the school's Christmas break...
So he comes up with the following exercise for you:
Let x1, x2, ..., xn be variables.
You're given an ordered list of constraints (equations) of the form xi = xj or xi = -xj. The constraints are transitive, so if you're given xi = xj and xj = xk, then xi = xk holds true even if not explicitly given in the list.
Then for each constraint between two variables xi and xj, you must mark it with:
In addition, we consider that a constraint xi = xi is always existing and a constraint xi = -xi is always contradicting.
The exercise is difficult, but your teacher is kind enough to give an example with explanations:
Let's say we have N = 4 variables and the following M = 7 constraints:
They're marked as follows:
Since we've reached a contradiction, the exercise stops.
The only thing that your teacher didn't knew is that you're really good at programming. In order to quickly solve all the exercises and get your time back, you've decided to write a program that automatically solves any instance of this exercise.
The first line of the input contains two integers N and M separated with a single whitespace character (1 ≤ N ≤ 106, 1 ≤ M ≤ 106). N is the number of variables (from x1 to xN). After the first line there are M more lines, each with two integers I and J separated with a whitespace character and with I∈ [1, N] and J∈ [-N, 1]∪ [1, N]. Each (I,J) pair represents a constraint. If J>0 then it represents the constraint xI = xJ. If J<0 then it represents the constraint xI = -x|J|. Although not necessary for the solution, you can assume that I<|J| holds for all input data if you want.
The output must be K lines, each with a single character which can be either N, E or C. The character at line i in the output is what you mark the i-th constraint of the input. It holds that 1≤ K ≤ N, depending on if there's a contradiction.
4 7 1 2 3 -4 1 -4 1 3 2 -4 2 -3 1 -4
N N N E E C
4 9 1 1 2 2 2 3 1 3 1 2 1 3 3 4 1 4 2 4
E E N N E E N E E