結果
問題 | No.1865 Make Cycle |
ユーザー |
![]() |
提出日時 | 2022-04-07 23:07:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,230 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 168,008 KB |
最終ジャッジ日時 | 2024-05-06 00:44:58 |
合計ジャッジ時間 | 9,124 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 334 ms
113,164 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 217 ms
105,472 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 381 ms
128,520 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 463 ms
153,748 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 320 ms
115,596 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 445 ms
144,980 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 38 ms
52,224 KB |
testcase_23 | WA | - |
ソースコード
from sys import stdin n, q, *indata = map(int, stdin.read().split()) offset = 0 left = 0 right = q+1 while right - left >= 2: mid = (right + left) // 2 g = [[] for i in range(n)] for i in range(mid): s, t = indata[i*2]-1,indata[i*2+1]-1 g[s].append(t) check = [0 for j in range(n)] cyclecheck = False for j in range(n): if check[j] == 0: que = [(j,0)] while que: now, inout = que.pop() if inout == 0: if check[now] == 0: que.append((now,1)) check[now] = 1 for k in g[now]: if check[k] == 1: cyclecheck = True break elif check[k] == 0: que.append((k,0)) if cyclecheck: break else: check[now] = 2 if cyclecheck: break if cyclecheck: right = mid else: left = mid if right == mid: print("{}".format(-1)) else: print("{}".format(right))