結果

問題 No.408 五輪ピック
ユーザー maspy
提出日時 2020-03-28 00:59:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 490 ms / 5,000 ms
コード長 891 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 30,088 KB
最終ジャッジ日時 2025-01-02 10:17:55
合計ジャッジ時間 4,218 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

N, M = map(int, readline().split())
m = map(int, read().split())
AB = tuple(zip(m, m))

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


dist_1 = set(graph[1])
parent = [set() for _ in range(N + 1)]
for u in dist_1:
    for v in graph[u]:
        if u == 1:
            continue
        parent[v].add(u)


def solve():
    for v1, v2 in AB:
        if v1 == 1 or v2 == 1:
            continue
        for u1, u2 in itertools.product(parent[v1], parent[v2]):
            if u1 == v2:
                continue
            if u2 == v1:
                continue
            if u1 == u2:
                continue
            return True
    return False


print('YES' if solve() else 'NO')
0