TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Given a directed graph with $N$ vertices and $M$ edges. $i$-th edge is $(a_ i, b_ i)$.

Calculate the dominator tree of this graph whose root is $S$.

Input Format

$N$ $M$ $S$
$a_ 0$ $b_ 0$
$a_ 1$ $b_ 1$
:
$a_ {M - 1}$ $b_ {M - 1}$

Output Format

$p_ 0$ $p_ 1$ $p_ 2$ ... $p_ {N - 1}$

$p_ i$ is the parent of vertex $i$. If we can not reach $i$ from $S$, print $-1$. $p_ S$ is $S$.

Sample Input 1

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

Sample Output 1

0 0 1 0 0

Sample Input 2

8 8 4
4 2
4 3
2 0
3 0
0 1
3 5
3 6
7 6

Sample Output 2

4 0 4 4 4 3 3 -1

Hints

  • $1 \leq N \leq 200,000$
  • $0 \leq M \leq 200,000$
  • $0 \leq S, a_ i, b_ i < N$

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 2097152 2097152
1 5000 2097152 2097152
2 5000 2097152 2097152
3 5000 2097152 2097152
4 5000 2097152 2097152
5 5000 2097152 2097152
6 5000 2097152 2097152
7 5000 2097152 2097152
8 5000 2097152 2097152
9 5000 2097152 2097152
10 5000 2097152 2097152
11 5000 2097152 2097152
12 5000 2097152 2097152