結果

問題 No.556 仁義なきサルたち
ユーザー dragonlaunchdragonlaunch
提出日時 2017-11-12 04:35:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 925 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2023-08-16 08:46:21
合計ジャッジ時間 5,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,564 KB
testcase_01 AC 17 ms
8,352 KB
testcase_02 AC 17 ms
8,260 KB
testcase_03 AC 17 ms
8,336 KB
testcase_04 AC 16 ms
8,264 KB
testcase_05 AC 20 ms
8,220 KB
testcase_06 AC 23 ms
8,192 KB
testcase_07 AC 25 ms
8,336 KB
testcase_08 AC 25 ms
8,316 KB
testcase_09 AC 102 ms
8,424 KB
testcase_10 AC 163 ms
8,460 KB
testcase_11 AC 198 ms
8,648 KB
testcase_12 AC 194 ms
8,496 KB
testcase_13 AC 738 ms
9,148 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 in group:
        group.remove(x)
    if y in group:
        group.remove(y)
    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