結果

問題 No.2664 Prime Sum
ユーザー miya145592miya145592
提出日時 2024-03-08 22:16:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 64,480 KB
最終ジャッジ日時 2024-03-08 22:16:27
合計ジャッジ時間 3,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 47 ms
53,460 KB
testcase_05 AC 43 ms
61,716 KB
testcase_06 AC 43 ms
61,732 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 40 ms
58,940 KB
testcase_09 AC 42 ms
61,572 KB
testcase_10 AC 42 ms
59,452 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 39 ms
53,460 KB
testcase_13 AC 44 ms
61,700 KB
testcase_14 AC 50 ms
64,480 KB
testcase_15 AC 48 ms
64,456 KB
testcase_16 AC 47 ms
64,456 KB
testcase_17 AC 37 ms
53,460 KB
testcase_18 AC 42 ms
61,572 KB
testcase_19 AC 44 ms
61,572 KB
testcase_20 AC 48 ms
64,480 KB
testcase_21 AC 48 ms
64,444 KB
testcase_22 AC 42 ms
61,704 KB
testcase_23 AC 49 ms
64,436 KB
testcase_24 AC 47 ms
64,436 KB
testcase_25 AC 48 ms
64,444 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 36 ms
53,460 KB
testcase_28 AC 36 ms
53,460 KB
testcase_29 AC 36 ms
53,460 KB
testcase_30 AC 35 ms
53,460 KB
testcase_31 AC 35 ms
53,460 KB
testcase_32 AC 36 ms
53,460 KB
testcase_33 AC 37 ms
53,460 KB
testcase_34 AC 37 ms
53,460 KB
testcase_35 AC 36 ms
53,460 KB
testcase_36 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(v, c, p):
    ret = True
    color[v] = c
    for nv in G[v]:
        if nv==p:
            continue
        if color[nv]==c:
            return False
        if color[nv]==1-c:
            continue
        ret = dfs(nv, 1-c, v)
        if ret==False:
            return ret
    return ret

import sys
input = sys.stdin.readline
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
G = [[] for _ in range(N)]
for a, b in AB:
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
color = [-1 for _ in range(N)]
for i in range(N):
    if color[i]!=-1:
        continue
    ret = dfs(i, 0, -1)
    if ret==False:
        print("No")
        exit()
print("Yes")
0