Submit Info #29055

Problem Lang User Status Time Memory
Cycle Detection pypy3 onakasuitacity AC 735 ms 108.54 MiB

ケース詳細
Name Status Time Memory
example_00 AC 50 ms 29.83 MiB
example_01 AC 48 ms 29.84 MiB
example_02 AC 50 ms 29.83 MiB
random_00 AC 442 ms 104.18 MiB
random_01 AC 735 ms 108.54 MiB
random_02 AC 336 ms 68.28 MiB
random_03 AC 140 ms 53.59 MiB
random_04 AC 264 ms 58.74 MiB
random_05 AC 410 ms 92.44 MiB
random_06 AC 506 ms 83.01 MiB
random_07 AC 92 ms 36.95 MiB
random_08 AC 324 ms 79.57 MiB
random_09 AC 199 ms 55.21 MiB
random_dag_00 AC 716 ms 96.43 MiB
random_dag_01 AC 733 ms 101.79 MiB
random_dag_02 AC 415 ms 70.71 MiB
random_dag_03 AC 145 ms 53.45 MiB
random_dag_04 AC 256 ms 57.85 MiB
random_dag_05 AC 691 ms 94.89 MiB
random_dag_06 AC 447 ms 80.76 MiB
random_dag_07 AC 95 ms 36.94 MiB
random_dag_08 AC 548 ms 82.70 MiB
random_dag_09 AC 343 ms 59.26 MiB
random_dag_dense_00 AC 271 ms 83.01 MiB
random_dag_dense_01 AC 255 ms 84.37 MiB
random_dag_dense_02 AC 263 ms 89.79 MiB
random_dag_dense_03 AC 246 ms 84.45 MiB
random_dag_dense_04 AC 301 ms 94.73 MiB
random_dense_00 AC 254 ms 83.00 MiB
random_dense_01 AC 241 ms 84.61 MiB
random_dense_02 AC 246 ms 89.66 MiB
random_dense_03 AC 254 ms 84.81 MiB
random_dense_04 AC 287 ms 94.62 MiB

import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): n, m = map(int, input().split()) E = [[] for _ in range(n)] i_to_m = [0] * m for i in range(m): u, v = map(int, input().split()) E[u].append((v, i)) i_to_m[i] = (u, v) state = [0] * n ans = [] def dfs(v): state[v] = -1 for nv, i in E[v]: if state[nv] == 0: dfs(nv) if state[nv] == -1: ans.append(i) return False state[v] = 1 return True all(dfs(v) for v in range(n)) if ans: while i_to_m[ans[0]][1] != i_to_m[ans[-1]][0]: ans.pop() print(len(ans), *ans[::-1], sep = '\n') else: print(-1) resolve()