結果

問題 No.2202 贅沢てりたまチキン
ユーザー titiatitia
提出日時 2023-02-03 23:16:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 892 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 27,268 KB
最終ジャッジ日時 2023-09-15 19:32:50
合計ジャッジ時間 11,284 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,964 KB
testcase_01 AC 15 ms
7,980 KB
testcase_02 AC 15 ms
7,800 KB
testcase_03 AC 15 ms
7,804 KB
testcase_04 AC 15 ms
7,784 KB
testcase_05 AC 15 ms
7,976 KB
testcase_06 AC 15 ms
7,832 KB
testcase_07 AC 15 ms
7,764 KB
testcase_08 AC 15 ms
7,788 KB
testcase_09 AC 15 ms
7,904 KB
testcase_10 AC 50 ms
27,148 KB
testcase_11 AC 16 ms
7,948 KB
testcase_12 AC 14 ms
7,952 KB
testcase_13 AC 15 ms
7,832 KB
testcase_14 AC 684 ms
27,140 KB
testcase_15 AC 687 ms
27,140 KB
testcase_16 AC 638 ms
27,196 KB
testcase_17 AC 715 ms
27,104 KB
testcase_18 AC 325 ms
17,856 KB
testcase_19 AC 340 ms
27,228 KB
testcase_20 AC 710 ms
27,140 KB
testcase_21 AC 712 ms
27,208 KB
testcase_22 AC 357 ms
8,228 KB
testcase_23 AC 419 ms
8,904 KB
testcase_24 AC 395 ms
8,412 KB
testcase_25 AC 892 ms
27,236 KB
testcase_26 AC 768 ms
27,268 KB
testcase_27 AC 686 ms
27,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())

# UnionFind

Group = [i for i in range(2*N+1)] # グループ分け
Nodes = [1]*(2*N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(M):
    a,b=map(int,input().split())
    Union(a,b+N)
    Union(a+N,b)

for i in range(1,N+1):
    if find(i)!=find(i+N):
        print("No")
        break
else:
    print("Yes")
0