Just Half is Enough
시간 제한2초메모리 제한2048 MB
방향 그래프가 주어질 때, 간선의 절반 이상에서 u가 v보다 앞서도록 정점을 나열하고, 그런 순서가 없으면 -1을 출력한다.
문제
Jacob is studying graph theory. Today he learned that a topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge from vertex to vertex , comes before in the ordering.
It is well-known that topological orderings exist only for graphs without cycles. But how do we generalize this concept for arbitrary graphs?
Jacob came up with the concept of a half-topological ordering: a linear ordering of the graph's vertices such that for at least half of all directed edges in the graph, comes before in the ordering.
In other words, if the graph has edges, and for a particular ordering, of them satisfy the condition above, then the ordering is called half-topological if .
Help Jacob find any half-topological ordering of the given graph, or report that none exist.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and , denoting the number of vertices and the number of edges in the graph (; ).
The -th of the following lines contains two integers and , describing an edge from vertex to vertex (; ). The graph does not contain multiple edges: each directed edge appears at most once. However, having both edges and is allowed.
It is guaranteed that the sum of over all test cases does not exceed , and the sum of over all test cases does not exceed .
출력
For each test case, print a single integer if the required half-topological ordering does not exist.
Otherwise, print distinct integers , describing the ordering of the given graph (). For at least of the edges , integer must come before integer in this list. If there are multiple answers, print any of them.