結果
問題 | No.1865 Make Cycle |
ユーザー | DrDrpilot |
提出日時 | 2022-03-08 13:48:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 790 ms / 3,000 ms |
コード長 | 693 bytes |
コンパイル時間 | 479 ms |
コンパイル使用メモリ | 87,096 KB |
実行使用メモリ | 182,128 KB |
最終ジャッジ日時 | 2023-09-30 19:37:58 |
合計ジャッジ時間 | 13,952 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 538 ms
132,864 KB |
testcase_01 | AC | 353 ms
112,648 KB |
testcase_02 | AC | 516 ms
133,448 KB |
testcase_03 | AC | 290 ms
124,116 KB |
testcase_04 | AC | 418 ms
139,072 KB |
testcase_05 | AC | 503 ms
147,380 KB |
testcase_06 | AC | 471 ms
132,356 KB |
testcase_07 | AC | 473 ms
132,872 KB |
testcase_08 | AC | 573 ms
148,208 KB |
testcase_09 | AC | 492 ms
148,600 KB |
testcase_10 | AC | 538 ms
144,672 KB |
testcase_11 | AC | 534 ms
146,832 KB |
testcase_12 | AC | 446 ms
127,016 KB |
testcase_13 | AC | 461 ms
126,868 KB |
testcase_14 | AC | 363 ms
121,268 KB |
testcase_15 | AC | 597 ms
150,892 KB |
testcase_16 | AC | 593 ms
152,460 KB |
testcase_17 | AC | 449 ms
122,944 KB |
testcase_18 | AC | 515 ms
158,836 KB |
testcase_19 | AC | 790 ms
182,128 KB |
testcase_20 | AC | 99 ms
71,484 KB |
testcase_21 | AC | 99 ms
71,660 KB |
testcase_22 | AC | 99 ms
71,608 KB |
testcase_23 | AC | 98 ms
71,396 KB |
ソースコード
from collections import deque n,q=map(int,input().split()) ab=[] for _ in range(q): a,b=map(int,input().split()) a-=1;b-=1 ab.append((a,b)) def check(x): deg=[0]*n g=[[] for _ in range(n)] q=deque() for a,b in ab[:x]: deg[b]+=1 g[a].append(b) for i in range(n): if deg[i]==0: q.append(i) ans=[] while q: now=q.popleft() ans.append(now) for to in g[now]: deg[to]-=1 if deg[to]==0: q.append(to) return len(ans)!=n r=q+1;l=0 while r-l>1: mid=(r+l)//2 if check(mid): r=mid else: l=mid if r>q: print(-1) else: print(r)