406834: GYM102566 K Security Cameras

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Security Camerastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

2020 has just begun, but the criminals are not resting! The city's biggest bank has just been robbed and the police are asking for your help to identify the thieves!

You know that the city is composed of intersections and directed roads in between them. You also know that there is a security camera situated in each intersection, but there are none on the roads.

Formally, the city can be represented as a directed graph with a security camera placed in each node.

You know the location of the bank and you also know the location where the thieves were last seen.

The police don't have time to go through the footage of all the security cameras so they ask you: regardless of the route they took, what are the intersections the robbers certainly passed through and in what order were they visited?

Input

The first line of the input will contain the number $$$T$$$, representing the number of test cases.

The first line of each test will contain two positive integers: $$$N$$$, the number of intersections, and $$$M$$$, the number of roads.

It is guaranteed that among all test cases $$$\sum N \leq 2*10^5$$$ and $$$\sum M \leq 2*10^6$$$.

The second line will contain two integers $$$A$$$, $$$B$$$, representing the bank location and the intersections where the thieves were last seen respectively. You may assume there is at least one route from intersection $$$A$$$ to intersection $$$B$$$.

The next $$$M$$$ lines will each contain a pair of integers $$$X$$$ and $$$Y$$$ ($$$X \neq Y$$$) describing a directed road from intersection $$$X$$$ to intersection $$$Y$$$. You may assume that the roads are pairwise distinct.

Output

The output file should consist of two lines for each test case.

On the first line you should output one number $$$S$$$ representing the number of cameras that certainly filmed the thieves.

The second line should contain $$$S$$$ numbers, the indices of intersections where said cameras are, in the same order they appeared in the thieves' path.

ExampleInput
1
5 5
1 5
1 2
1 3
2 4
3 4
4 5
Output
3
1 4 5 
Note

The example consists of only one test case.

The bank is situated in intersection $$$1$$$ and the criminals were last seen in intersection $$$5$$$.

The routes the thieves could have taken are $$$1-2-4-5$$$ and $$$1-3-4-5$$$.

There are $$$3$$$ cameras that certainly saw them and they are situated in intersections $$$1$$$, $$$4$$$ and $$$5$$$.

加入题单

算法标签: