結果

問題 No.2202 贅沢てりたまチキン
ユーザー titiatitia
提出日時 2023-02-03 23:00:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 753 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 17,816 KB
最終ジャッジ日時 2023-09-15 19:12:31
合計ジャッジ時間 6,792 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 16 ms
7,840 KB
testcase_02 AC 17 ms
7,772 KB
testcase_03 WA -
testcase_04 AC 15 ms
7,808 KB
testcase_05 AC 16 ms
7,896 KB
testcase_06 WA -
testcase_07 AC 15 ms
7,700 KB
testcase_08 AC 15 ms
7,772 KB
testcase_09 AC 15 ms
7,796 KB
testcase_10 AC 34 ms
17,656 KB
testcase_11 AC 15 ms
7,900 KB
testcase_12 AC 15 ms
7,816 KB
testcase_13 WA -
testcase_14 AC 435 ms
17,648 KB
testcase_15 WA -
testcase_16 AC 399 ms
17,644 KB
testcase_17 AC 403 ms
17,640 KB
testcase_18 WA -
testcase_19 AC 221 ms
17,772 KB
testcase_20 WA -
testcase_21 AC 378 ms
17,716 KB
testcase_22 AC 268 ms
7,892 KB
testcase_23 AC 296 ms
8,464 KB
testcase_24 AC 289 ms
8,304 KB
testcase_25 AC 520 ms
17,652 KB
testcase_26 WA -
testcase_27 AC 436 ms
17,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(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)

if Nodes[find(1)]==N and M>=N:
    print("Yes")
else:
    print("No")
0