AT_ttpc2024_1_a Don't Detect Cycle

Description

You are given a graph $ G $ consisting of $ N $ vertices numbered $ 1, 2, \ldots, N $ . Initially, $ G $ has no edges. You will add $ M $ undirected edges to $ G $ . The final shape of the graph is predetermined, and the $ i $ -th edge to be added $ (1 > You must be able to add all $ M $ edges to $ G $ by following this procedure: > > - For $ i = 1, 2, \dots, M $ , repeat the following: > 1. If there is already a cycle in $ G $ containing either vertex $ u_{P_i} $ or vertex $ v_{P_i} $ , the condition is not satisfied, and the procedure ends. > 2. Add edge $ P_i $ (the undirected edge connecting $ u_{P_i} $ and $ v_{P_i} $ ) to $ G $ . You are given $ T $ test cases; solve each of them. What is a cycle? A cycle in $ G $ is defined as a sequence of vertices $ (v_0, \dots, v_{L - 1}) $ and a sequence of edges $ (e_0, \dots, e_{L - 1}) $ that satisfy the following conditions: - $ L \ge 1 $ - $ i \neq j \implies v_i \neq v_j, e_i \neq e_j $ - For $ 0 \le i \le L - 2 $ , edge $ e_i $ connects vertices $ v_i $ and $ v_{i+1} $ - Edge $ e_{L-1} $ connects vertices $ v_{L-1} $ and $ v_0 $ What does it mean for a graph to be simple? A graph $ G $ is simple if it contains no self-loops or multiple edges.

Input Format

The input is given from Standard Input in the following format: > $ T $ $ \text{case}_1 $ $ \text{case}_2 $ $ \vdots $ $ \text{case}_T $ Here, $ \text{case}_i\ (1

Output Format

For each test case, if a permutation $ (P_1, P_2, \ldots, P_M) $ satisfying the conditions exists, output such a $ P $ separated by spaces. If no such permutation exists, output `-1`.

Explanation/Hint

### Subtasks $ 30 $ points will be awarded for passing the test set satisfying: - $ T \le 50 $ - For each test case: - $ N \le 100 $ - $ M \le 100 $ - The sum of $ N $ over all test cases is at most $ 100 $ . - The sum of $ M $ over all test cases is at most $ 100 $ . ### Sample Explanation 1 The given graph has the following shape: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_ttpc2024_1_a/7977fc1260c88ae594d570f0bf51f5055ae637ceac9de899dbc87a18c332fcaa.png) If we add the edges in the order $ P = (1, 2, 3, 4) $ , the conditions are satisfied as shown below: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_ttpc2024_1_a/f26da3f9bad37ebfaaccd03b05344fccba8cb5f3b63817e63983c68a7a96f6c1.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_ttpc2024_1_a/ee96679db48d1511b6553e4424dd39cd07d0f8b49ed7bae5a5566f535ecf434e.png) Thus, `1 2 3 4` is one valid output. However, if we add edges in the order $ P = (2, 3, 4, 1) $ , a cycle containing vertex $ 2 $ is created before edge $ 1 $ can be added, so the conditions are not satisfied. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_ttpc2024_1_a/6730f197e8ffeaac78001c488d93862eb47a9a84d1b1bdaa0af22122e143310a.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_ttpc2024_1_a/065e30a7abb10bff9d9a095b21235a568807396d8a66d96649f1ee1711b8dbb8.png) Other valid outputs include $ P = (1, 4, 3, 2) $ or $ P = (2, 4, 1, 3) $ . ### Sample Explanation 2 If no valid $ P $ exists, output `-1`. Note that the graph is not necessarily connected. ### Constraints - All input values are integers. - $ 1 \le T \le 2000 $ - For each test case: - $ 2 \le N \le 4000 $ - $ 1 \le M \le 4000 $ - $ 1 \le u_i, v_i \le N\ (1