結果
問題 | No.1865 Make Cycle |
ユーザー |
|
提出日時 | 2024-08-03 01:36:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,413 bytes |
コンパイル時間 | 522 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 99,892 KB |
最終ジャッジ日時 | 2024-08-03 01:36:14 |
合計ジャッジ時間 | 7,741 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 14 |
ソースコード
## https://yukicoder.me/problems/no/1865from collections import dequedef solve(N, next_nodes, border_q):queue = deque()passed = [-1] * Np_id = 0for s_i in range(N):if passed[s_i] == -1:queue.append(s_i)passed[s_i] = p_idwhile len(queue) > 0:v = queue.popleft()for w, q in next_nodes[v].items():if q > border_q:continueif w == s_i:return Trueif passed[w] == -1:passed[w] = p_idqueue.append(w)p_id += 1return Falsedef main():N, Q = map(int, input().split())next_nodes = [{} for _ in range(N)]for i in range(Q):a, b = map(int, input().split())a -= 1b -= 1if b not in next_nodes[a]:next_nodes[a][b] = i# 全て繋げた状態でans = solve(N, next_nodes, Q - 1)if not ans:print(-1)returnlow = 0high = Q - 1while high - low > 1:mid = (high + low) // 2if solve(N, next_nodes, mid):high = midelse:low = midif solve(N, next_nodes, low):print(low + 1)else:print(high + 1)if __name__ == "__main__":main()