結果

問題 No.556 仁義なきサルたち
ユーザー mbanmban
提出日時 2017-08-12 08:44:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-21 05:52:19
合計ジャッジ時間 1,872 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 71 ms
11,264 KB
testcase_20 AC 72 ms
11,264 KB
testcase_21 AC 70 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

line=input().split()
n=int(line[0])
m=int(line[1])

node=[i for i in range(n)]
size=[1 for i in range(n)]

def root(a):
    if node[a]==a:
        return a
    else:
        return root(node[a])
        
def u(a,b):
    size[a]+=size[b]
    node[b]=a

def union(a,b):
    a=root(a)
    b=root(b)
    if a!=b:
        if size[a]>size[b]:
            u(a,b)
        elif size[a]<size[b]:
            u(b,a)
        else:
            if a<b:
                u(a,b)
            else:
                u(b,a)
                
for i in range(m):
    line=input().split()
    a=int(line[0])-1
    b=int(line[1])-1
    union(a,b)
    
for i in node:
    print(i+1)
    
0