結果
問題 | No.1865 Make Cycle |
ユーザー |
👑 |
提出日時 | 2022-03-23 14:40:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 762 ms / 3,000 ms |
コード長 | 1,018 bytes |
コンパイル時間 | 329 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 110,140 KB |
最終ジャッジ日時 | 2024-10-11 12:50:49 |
合計ジャッジ時間 | 13,813 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
import syssys.setrecursionlimit(10 ** 9)import pypyjitpypyjit.set_param('max_unroll_recursion=-1')n, q = map(int, input().split())edges = [[] for _ in range(n)]for i in range(1, q + 1):a, b = map(int, input().split())edges[a - 1].append((b - 1, i))used = [False] * nused2 = [False] * ndef dfs(pos, x):used2[pos] = Truefor npos, i in edges[pos]:if i > x:continueif used2[npos]:return Trueif used[npos]:continueused[npos] = Trueif dfs(npos, x):return Trueused2[pos] = Falsereturn Falsedef ok(x):global used, used2used = [False] * nused2 = [False] * nfor i in range(n):if used[i]:continueused[i] = Trueif dfs(i, x):return Truereturn Falsel = 0r = q + 1while r - l > 1:mid = (l + r) // 2if ok(mid):r = midelse:l = midif r == q + 1:print(-1)else:print(r)