結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:56:16 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,170 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,272 KB |
実行使用メモリ | 94,408 KB |
最終ジャッジ日時 | 2025-04-16 00:58:03 |
合計ジャッジ時間 | 3,238 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 2 MLE * 18 |
ソースコード
import sys from collections import defaultdict def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 M = int(input[idx]) idx += 1 adj = defaultdict(list) for _ in range(M): u = int(input[idx]) idx += 1 v = int(input[idx]) idx += 1 adj[u].append(v) adj[v].append(u) # Collect neighbors of 1 S = set(adj[1]) if len(S) < 2: print("NO") return # Precompute for each node, the set of neighbors in S s_neighbors = defaultdict(set) for node in adj: for neighbor in adj[node]: if neighbor in S: s_neighbors[node].add(neighbor) # Check all nodes except 1 for x in range(1, N+1): if x == 1: continue d_set = s_neighbors[x] if not d_set: continue for y in adj[x]: a_set = s_neighbors[y] if not a_set: continue for a in a_set: if a not in d_set: print("YES") return print("NO") if __name__ == "__main__": main()