규칙에 따라 수열을 두 그룹으로 나누는 작업
https://codeup.kr/problem.php?id=4763
def enemy_relation(enemy, relation):
n_enemy = []
for m in enemy:
n_enemy.append(sum([1 if m in relation[k][1:] else 0 for k in enemy]))
return enemy
N = int(input())
relation = {i+1:list(map(int,input().split())) for i in range(N)}
unsocial_list = sorted(relation,key= lambda x: relation[x][0],reverse= True)
room= [[],[]]
monkey = []
for n in unsocial_list:
if n not in monkey:
enemy = relation[n][1:]
room_n = 1 if sum([True if en in room[0] else False for en in enemy]) > 0 else 0
enemy = [en for en in enemy if not en in monkey]
monkey += (enemy + [n])
if len(enemy) == 1:
room[room_n] += [n]
room[abs(room_n-1)] += enemy
elif len(enemy) > 1:
follow = enemy_relation(enemy,relation)
room[room_n] += [n,follow[0]]
room[abs(room_n-1)] += follow[1:]
else:
room[room_n] += [n]
if len(monkey) == N:
break
if not room[1]:
room[1] += [room[0][0]]
del room[0][0]
print(' '.join(map(str,sorted(room[0]))))
print(' '.join(map(str,sorted(room[1]))))
fail...
어디서 틀린 것일까
Graph 문제로 보임
Graph 자료 구조 공부 후 재도전!