Topological Order Or Cycle

Programming Interview Hard 4 views
Back to Questions

Problem Description

For each testcase you get a directed graph. If topological order exists, output one order. If cycle exists, output CYCLE.

Input Format

First integer t. For each: n m then m edges u v (u->v).

Output Format

t lines: order or CYCLE.

Sample Test Case

Input:
2 4 3 1 2 1 3 3 4 3 3 1 2 2 3 3 1
Output:
1 2 3 4 CYCLE

Constraints

Sum of n+m over all testcases

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next