結果

問題 No.556 仁義なきサルたち
ユーザー dragonlaunchdragonlaunch
提出日時 2017-11-12 05:10:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 15,352 KB
最終ジャッジ日時 2023-08-16 09:14:24
合計ジャッジ時間 10,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,352 KB
testcase_01 AC 16 ms
8,184 KB
testcase_02 AC 16 ms
8,232 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 19 ms
8,292 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 72 ms
8,232 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 296 ms
9,024 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
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))
monk = monkey.copy()
group = []
for i in range(N):
    group.append([(monkey[i])])
#print(group,battle)
def bat(a,b):
    if a == b:
        return None
    elif len(a) == len(b):
        if a[0] < b[0]:
            for i in b:
                monk[i-1] = a[0]
            return a + b
        if b[0] < a[0]:
            for i in a:
                monk[i-1] = b[0]
            return b + a
    elif len(a) > len(b):
        for i in b:
            monk[i-1] = a[0]
        return a + b
    elif len(b) > len(a):
        for i in a:
            monk[i-1] = b[0]
        return b + a
for i in range(M):
    count = 0
    for j in range(len(group)):
        if battle[i][0] in group[j]:
            x = group[j]
            count +=1
        if battle[i][1] in group[j]:
            y = group[j]
            count+=1
        if count == 2:
            break
    if x != y:
        group.remove(x)
        group.remove(y)
    group.append(bat(x,y))

for i in range(N):
    print(monk[i])
0