結果

問題 No.2202 贅沢てりたまチキン
ユーザー lam6er
提出日時 2025-03-20 21:11:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,524 KB
実行使用メモリ 106,400 KB
最終ジャッジ日時 2025-03-20 21:11:35
合計ジャッジ時間 3,954 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

n, m = map(int, sys.stdin.readline().split())

adj = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    adj[a].append(b)
    adj[b].append(a)

color = [-1] * (n + 1)

for u in range(1, n + 1):
    if color[u] == -1:
        queue = deque([u])
        color[u] = 0
        is_bipart = True
        found_conflict = False
        while queue and not found_conflict:
            v = queue.popleft()
            for nei in adj[v]:
                if color[nei] == -1:
                    color[nei] = 1 - color[v]
                    queue.append(nei)
                else:
                    if color[nei] == color[v]:
                        found_conflict = True
                        is_bipart = False
                        break
            if found_conflict:
                break
        if is_bipart:
            print("No")
            sys.exit()

print("Yes")
0