#P15194. [SWERC 2019] Bird Watching
[SWERC 2019] Bird Watching
题目描述
Kiara studies an odd species of birds which travel in a very peculiar way. Their movements are best explained using the language of graphs: there exists a directed graph where the nodes are trees, and a bird can only fly from a tree to when is an edge of .
Kiara does not know the real graph governing the flight of these birds but, in her previous field study, Kiara has collected data from the journey of many birds. Using this, she has devised a graph explaining how they move. Kiara has spent so much time watching them that she is confident that if a bird can fly directly from to , then she has witnessed at least one such occurrence. However, it is possible that a bird flew from to to but she only witnessed the stops and and then added to . It is also possible that a bird flew from to to to and she only witnessed and , and added to , etc. To sum up, she knows that contains all the edges of and that might contain some other edges for which there is a path from to in (note that might not contain all such edges).
For her next field study, Kiara has decided to install her base next to a given tree . To be warned of the arrival of birds on , she would also like to install detectors on the trees where the birds can come from (i.e. the trees such that there is an edge in ). As detectors are not cheap, she only wants to install detectors on the trees for which she is sure that belongs to .
Kiara is sure that an edge belongs to when is an edge of and all the paths in starting from and ending in use the edge . Kiara asks you to compute the set of trees for which she is sure that is an edge of .
输入格式
The input describes the graph . The first line contains three space-separated integers , , and : is the number of nodes of , is the number of edges of and is the node corresponding to the tree on which Kiara will install her base.
The next lines describe the edges of the graph . Each contains two space-separated integers and ( and ) stating that . It is guaranteed that the same pair will not appear twice.
输出格式
Your output should describe the set . The first line should contain an integer , which is the number of nodes in , followed by lines, each containing a different element of . The elements of should be printed in increasing order, with one element per line.
3 3 2
0 1
0 2
1 2
1
1
6 8 2
0 1
0 2
1 2
2 0
2 3
3 4
4 2
2 5
2
1
4
提示
Sample Explanation 1
The graph corresponding to this example is depicted on the right. The node belongs to because the (only) path from to uses . The node does not belong to because the path does not use the edge .
:::align{center}
:::
Sample Explanation 2
The graph corresponding to this example is depicted on the right. For the same reason as in Sample 1, the node does not belong to while does. The nodes and do not belong to because we do not have edges or . Finally belongs to because all paths from to use the edge .
:::align{center}
:::
Limits
- ;
- .