## BREAK - Breaking in

Mayco has recently been hired as a security consultant for a well-known software company. At the moment, he's working on his first assignment – trying to determine which of the company's servers would be the best targets for potential attackers. It is a bit difficult, though, because some of the servers "trust" some of the others. If an attacker compromises a server, he or she can also freely access all servers that trust it (and servers that trust them, and so on).

By definition, the importance of a server S is the number of servers the attacker would be able to access if he compromised S. The most important servers are those with the highest importance. (Note that there can be more than one most important server. This is also illustrated in the example below.)

### Problem specification

The network consists of N computers, numbered 1 to N, inclusive. The trust between computers is described by M ordered pairs (A,B) of numbers, denoting that computer A trusts computer B. The trust is not assumed to be mutual – i.e., if a computer A trusts computer B, it does not necessarily imply that computer B trusts computer A.

### Input specification

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.

Each test case starts with a line containing the numbers N and M(1<= N <=9000, 1<= M <= 52000). Each of the following M lines contains two integers, A and B, denoting that computer A trusts computer B.

### Output specification

For each test case, the output shall contain one line with the numbers of all of the most important servers. The numbers must be listed in increasing order and separated by single spaces.

### Example

input:2 5 4 3 1 3 2 4 3 5 3 6 5 1 2 2 3 3 1 1 4 5 6output:1 2 4

### Note

Blue Mary has found a pruning which will make the program very efficient. So the time limit of the hard test case is changed from 60 seconds to 15 seconds. If you have some even harder test case, please send it to me, and I'll add it to the standard input file.

hide comments

shubham7iitj:
2015-09-19 11:58:42
Time limit is very strict. Linear time solutions also not passing. |

Added by: | Fudan University Problem Setters |

Date: | 2008-05-24 |

Time limit: | 0.5s-3s |

Source limit: | 50000B |

Memory limit: | 1536MB |

Cluster: | Cube (Intel G860) |

Languages: | All except: C99 ERL JS-RHINO NODEJS PERL6 VB.NET |

Resource: | IPSC 2008 |