結果
問題 | No.1865 Make Cycle |
ユーザー | puzneko |
提出日時 | 2022-04-07 23:08:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 634 ms / 3,000 ms |
コード長 | 1,229 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 87,032 KB |
実行使用メモリ | 176,272 KB |
最終ジャッジ日時 | 2023-08-18 19:02:34 |
合計ジャッジ時間 | 11,133 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 396 ms
124,700 KB |
testcase_01 | AC | 281 ms
103,816 KB |
testcase_02 | AC | 430 ms
129,612 KB |
testcase_03 | AC | 243 ms
106,536 KB |
testcase_04 | AC | 424 ms
148,436 KB |
testcase_05 | AC | 534 ms
176,272 KB |
testcase_06 | AC | 430 ms
135,612 KB |
testcase_07 | AC | 390 ms
129,708 KB |
testcase_08 | AC | 373 ms
122,680 KB |
testcase_09 | AC | 532 ms
163,616 KB |
testcase_10 | AC | 509 ms
154,332 KB |
testcase_11 | AC | 496 ms
149,144 KB |
testcase_12 | AC | 360 ms
121,688 KB |
testcase_13 | AC | 368 ms
121,828 KB |
testcase_14 | AC | 360 ms
123,972 KB |
testcase_15 | AC | 505 ms
136,492 KB |
testcase_16 | AC | 517 ms
142,996 KB |
testcase_17 | AC | 445 ms
123,760 KB |
testcase_18 | AC | 541 ms
163,964 KB |
testcase_19 | AC | 634 ms
158,596 KB |
testcase_20 | AC | 66 ms
71,476 KB |
testcase_21 | AC | 67 ms
71,532 KB |
testcase_22 | AC | 69 ms
71,516 KB |
testcase_23 | AC | 67 ms
71,244 KB |
ソースコード
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 == q+1: print("{}".format(-1)) else: print("{}".format(right))