結果
問題 | No.1865 Make Cycle |
ユーザー | puzneko |
提出日時 | 2022-04-07 23:07:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,230 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 86,800 KB |
実行使用メモリ | 176,428 KB |
最終ジャッジ日時 | 2023-08-18 19:02:04 |
合計ジャッジ時間 | 11,665 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 413 ms
124,620 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 256 ms
106,488 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 461 ms
135,664 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 496 ms
154,564 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 370 ms
121,476 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 533 ms
142,880 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 66 ms
71,432 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))