結果
| 問題 |
No.408 五輪ピック
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:33:31 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,361 bytes |
| コンパイル時間 | 183 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 86,128 KB |
| 最終ジャッジ日時 | 2025-06-12 16:34:06 |
| 合計ジャッジ時間 | 7,528 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 WA * 2 MLE * 3 |
ソースコード
import sys
from collections import defaultdict
def main():
N, M = map(int, sys.stdin.readline().split())
adj = defaultdict(list)
for _ in range(M):
u, v = map(int, sys.stdin.readline().split())
adj[u].append(v)
adj[v].append(u)
# Collect neighbors of 1
S = adj[1]
if len(S) < 2:
print("NO")
return
# Precompute for each y, the set of S nodes connected to y
pre = defaultdict(set)
for z in S:
for y in adj[z]:
pre[y].add(z)
# Iterate through each a in S
for a in S:
# Iterate through each neighbor x of a, excluding 1
for x in adj[a]:
if x == 1:
continue
# Iterate through each neighbor y of x, excluding a
for y in adj[x]:
if y == a:
continue
# Check if y has any S nodes connected to it
if pre[y]:
# Check if any of those S nodes is not a
has_valid = False
for z in pre[y]:
if z != a:
has_valid = True
break
if has_valid:
print("YES")
return
print("NO")
if __name__ == "__main__":
main()
gew1fw