結果

問題 No.556 仁義なきサルたち
ユーザー dragonlaunchdragonlaunch
提出日時 2017-11-12 04:38:33
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 936 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 15,312 KB
最終ジャッジ日時 2023-08-16 08:46:28
合計ジャッジ時間 5,614 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,312 KB
testcase_01 AC 16 ms
8,268 KB
testcase_02 AC 16 ms
8,348 KB
testcase_03 AC 16 ms
8,288 KB
testcase_04 AC 16 ms
8,324 KB
testcase_05 AC 20 ms
8,288 KB
testcase_06 AC 22 ms
8,368 KB
testcase_07 AC 24 ms
8,388 KB
testcase_08 AC 24 ms
8,268 KB
testcase_09 AC 99 ms
8,432 KB
testcase_10 AC 153 ms
8,440 KB
testcase_11 AC 184 ms
8,660 KB
testcase_12 AC 184 ms
8,652 KB
testcase_13 AC 711 ms
9,016 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import time
N,M = [int(i) for i in input().split()]
battle = []
for i in range (M):
    battle.append(list(int(i) for i in input().split()))
monkey = list(range(1,N+1))
group = []
for i in range(N):
    group.append([(monkey[i])])
#print(group,battle)
def bat(a,b):
    if a == b:
        return a
    elif len(a) == len(b):
        if a[0] < b[0]:
            return a + b
        if b[0] < a[0]:
            return b + a
    elif len(a) > len(b):
        return a + b
    elif len(b) > len(a):
        return b + a

for i in range(M):
    for j in range(len(group)):
        if battle[i][0] in group[j]:
            x = group[j]
        if battle[i][1] in group[j]:
            y = group[j]
    if x != y:
        group.remove(x)
        group.remove(y)
    else:
        group.remove(x)
    group.append(bat(x,y))
for i in group:
    for j in i:
        monkey[j-1] = group[group.index(i)][0]
for i in range(N):
    print(monkey[i])
0