結果
問題 |
No.2780 The Bottle Imp
|
ユーザー |
|
提出日時 | 2024-06-06 23:04:00 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,112 bytes |
コンパイル時間 | 505 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 42,680 KB |
最終ジャッジ日時 | 2024-12-27 13:32:40 |
合計ジャッジ時間 | 7,397 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 WA * 4 |
ソースコード
def can_spread_to_all(N, connections): from collections import deque # グラフの隣接リストを構築 graph = [[] for _ in range(N + 1)] for i, conn in enumerate(connections, 1): for person in conn: graph[i].append(person) # BFSで到達可能なノードを探索 visited = [False] * (N + 1) queue = deque([1]) visited[1] = True while queue: current = queue.popleft() for neighbor in graph[current]: if not visited[neighbor]: visited[neighbor] = True queue.append(neighbor) # 全てのノードに訪問できたかチェック return all(visited[1:]) # 入力を読み込む import sys input = sys.stdin.read data = input().split() N = int(data[0]) index = 1 connections = [] for _ in range(N): M = int(data[index]) if M == 0: connections.append([]) else: connections.append([int(data[i]) for i in range(index + 1, index + M + 1)]) index += M + 1 if can_spread_to_all(N, connections): print("Yes") else: print("No")