結果

問題 No.556 仁義なきサルたち
ユーザー dragonlaunchdragonlaunch
提出日時 2017-11-12 05:13:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,104 KB
最終ジャッジ日時 2024-05-03 18:04:30
合計ジャッジ時間 7,745 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
16,256 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 35 ms
10,752 KB
testcase_07 AC 37 ms
10,880 KB
testcase_08 AC 37 ms
10,880 KB
testcase_09 AC 87 ms
10,880 KB
testcase_10 AC 144 ms
11,008 KB
testcase_11 AC 183 ms
11,008 KB
testcase_12 AC 181 ms
11,008 KB
testcase_13 AC 314 ms
11,520 KB
testcase_14 TLE -
testcase_15 TLE -
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))
monk = monkey.copy()
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]:
            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)
    if x == y:
        group.remove(x)
    group.append(bat(x,y))

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