結果

問題 No.2202 贅沢てりたまチキン
ユーザー ntudantuda
提出日時 2023-02-05 13:41:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,276 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 111,524 KB
最終ジャッジ日時 2023-09-17 06:15:15
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
75,352 KB
testcase_01 AC 65 ms
71,128 KB
testcase_02 AC 61 ms
71,072 KB
testcase_03 AC 59 ms
71,380 KB
testcase_04 AC 61 ms
71,072 KB
testcase_05 AC 63 ms
71,092 KB
testcase_06 AC 60 ms
71,012 KB
testcase_07 AC 60 ms
71,044 KB
testcase_08 AC 61 ms
71,336 KB
testcase_09 AC 58 ms
71,004 KB
testcase_10 AC 96 ms
111,524 KB
testcase_11 AC 61 ms
71,044 KB
testcase_12 AC 61 ms
71,228 KB
testcase_13 AC 58 ms
71,072 KB
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
                else:
                    return False
            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