結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:54:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,170 bytes |
| 記録 | |
| コンパイル時間 | 322 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 94,348 KB |
| 最終ジャッジ日時 | 2025-04-16 00:56:00 |
| 合計ジャッジ時間 | 3,378 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 2 MLE * 20 |
ソースコード
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()
lam6er