Problem F
The Elk
You are in a forest. In this forest there is also a pair of elks - a cow (an adult female) and her calf (child). As most people know, it is dangerous to get between a cow and her calf, but it is not always clear how to avoid it.
We model our forest as consisting of $N$ locations, and $M$ direct connections between these locations. These connections can be travelled in either direction. The locations are numbered $0$ to $N-1$ and connections are numbered $0$ to $M-1$.
We define a path from the cow to the calf as a series of locations, $p_0, p_1, p_2, \ldots , p_ k$ such that:
-
$p_0$ is the location of the cow
-
$p_ k$ is the location of the calf.
-
For each $i$ satisfying $0 \le i < k$, there is a direct connection between the locations $p_ i$ and $p_{i+1}$
-
None of the connections from point 3 are repeated within the path. Note that we do allow locations to be repeated within the path.
Clearly, any location that is on any such path is a dangerous place to be, as the cow could consider you to be between her and the calf. Your task is to find all the safe locations - that is, the locations that are not on any such path.
Input
The first line contains four integers, $N, M, A, B$. $N$ and $M$ are the number of locations and direct connections respectively, while $A$ and $B$ are the current locations of the cow and the calf respectively.
The following $M$ lines, numbered from $0$ to $M-1$, each describe one of the $M$ connections. The $i$th of these line contains two integers $U_ i$ and $V_ i$, indicating that $i$th connection is between locations $U_ i$ and $V_ i$.
Output
The first line of output should contain a single integer $S$, the number of locations in the forest where it is safe to be.
The next $S$ lines of output should be a list of all the safe locations, one location per line, in increasing numerical order.
Constraints
$2 \le N \le 5 \cdot
10^4$
$2 \le M \le 10^5$
$0 \le U_ i, V_ i < N$
for all $i$.
$0 \leq A,B \leq N-1$
$U_ i \neq V_ i$ for all
$i$.
There will be at most one direct connection between any pair of
locations.
There will always be at least one path from the cow to the
calf.
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group |
Point value |
Constraints |
$1$ |
$10$ |
$N \le 10$, $M \le 45$ |
$2$ |
$20$ |
$M = N-1$ and the graph is connected. |
$3$ |
$30$ |
$N \le 200$, $M \le 500$ |
$4$ |
$40$ |
No additional constraints. |
Sample Input 1 | Sample Output 1 |
---|---|
9 10 0 7 1 0 2 0 0 3 5 4 4 3 4 6 3 6 6 7 7 3 7 8 |
4 1 2 5 8 |
Sample Input 2 | Sample Output 2 |
---|---|
8 8 2 3 0 1 0 2 1 2 2 3 3 4 3 5 4 5 6 7 |
2 6 7 |