結果
| 問題 |
No.408 五輪ピック
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:02:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,156 bytes |
| コンパイル時間 | 195 ms |
| コンパイル使用メモリ | 82,396 KB |
| 実行使用メモリ | 87,444 KB |
| 最終ジャッジ日時 | 2025-06-12 19:02:51 |
| 合計ジャッジ時間 | 9,711 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 MLE * 11 -- * 4 |
ソースコード
import sys
from sys import stdin
from collections import defaultdict
def main():
N, M = map(int, stdin.readline().split())
adj = defaultdict(set)
for _ in range(M):
a, b = map(int, stdin.readline().split())
adj[a].add(b)
adj[b].add(a)
# Get neighbors of vertex 1
S = adj.get(1, set())
if not S:
print("NO")
return
S_set = S # Using a set for O(1) lookups
# Check all possible paths of the form 1 -> a -> b -> c -> d -> 1
for a in S:
for b in adj[a]:
if b == 1:
continue
# b is a neighbor of a (excluding 1)
for c in adj[b]:
if c == 1 or c == a:
continue
# c is a neighbor of b (excluding 1 and a)
for d in adj[c]:
if d == 1 or d == b:
continue
# d is a neighbor of c (excluding 1 and b)
if d in S_set and d != a and d != c:
print("YES")
return
print("NO")
if __name__ == "__main__":
main()
gew1fw