結果

問題 No.556 仁義なきサルたち
ユーザー dragonlaunchdragonlaunch
提出日時 2017-11-12 04:34:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 924 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2023-08-16 08:46:14
合計ジャッジ時間 6,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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