![]() |
||||||||||
|
||||||||||
DZY Loves Topological SortingTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1352 Accepted Submission(s): 450 Problem Description A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge $(u\rightarrow v)$ from vertex $u$ to vertex $v$, $u$ comes before $v$ in the ordering. Now, DZY has a directed acyclic graph(DAG). You should find the lexicographically largest topological ordering after erasing at most $k$ edges from the graph. Input The input consists several test cases. ($TestCase\leq 5$) The first line, three integers $n,m,k(1\leq n,m\leq 10^5, 0\leq k\leq m)$. Each of the next $m$ lines has two integers: $u,v(u\not= v, 1\leq u,v\leq n)$, representing a direct edge$(u\rightarrow v)$. Output For each test case, output the lexicographically largest topological ordering. Sample Input
Sample Output
Hint Case 1. Erase the edge (2->3),(4->5). And the lexicographically largest topological ordering is (5,3,1,2,4). Source | ||||||||||
|