結果

問題 No.2202 贅沢てりたまチキン
ユーザー ntudantuda
提出日時 2023-02-05 13:36:16
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,221 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 468,544 KB
最終ジャッジ日時 2023-09-17 06:11:19
合計ジャッジ時間 10,125 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
71,204 KB
testcase_01 AC 58 ms
71,112 KB
testcase_02 AC 59 ms
71,044 KB
testcase_03 AC 61 ms
71,232 KB
testcase_04 AC 60 ms
71,128 KB
testcase_05 AC 66 ms
71,424 KB
testcase_06 RE -
testcase_07 AC 76 ms
70,980 KB
testcase_08 AC 64 ms
71,296 KB
testcase_09 AC 64 ms
71,020 KB
testcase_10 AC 96 ms
111,724 KB
testcase_11 AC 60 ms
71,112 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(200050)

def find(x):
    if P[x] == x: return x
    else:
        P[x] = find(P[x]) #経路圧縮
        return P[x]
        # return find(P[x]) #経路圧縮なし

def same(x,y):
    return find(x) == find(y)

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if x > y: x,y = y,x
    P[y] = x

def parents():
    Ps = set()
    for i in range(N):
        a = find(i)
        if a not in Ps:
            Ps.add(a)
    return Ps

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]
P = [i for i in range(N)]
visited = [False] * N

E = [[] for _ in range(N)]
for a,b in AB:
    a -= 1; b -= 1
    E[a].append(b)
    E[b].append(a)
    unite(a,b)

Ps = parents()

def dfs(u,p):
    for v in E[u]:
        if v != p:
            if v in P1:
                if (len(P1) - P1.index(v)) % 2 == 1:
                    return True
            P1.append(v)
            visited[v] = True
            if dfs(v,u):
                return True
            P1.pop(-1)
            visited[v] = False
    return False

for i in Ps:
    P1 = [i]
    visited[i] = True
    if dfs(i,-1) == False:
        print("No")
        exit()
print("Yes")
0