백준
n = int(input())
m = int(input())
f = [[] for i in range(n+1)]
ans = [1]
for i in range(m):
a, b = map(int, input().split())
f[a].append(b)
f[b].append(a)
ans+=f[1]
for i in f[1]:
ans += f[i]
print(len(set(ans))-1)
프로그래머스
def solution(phone_book):
answer = True
n = len(phone_book)
phone_book = sorted(phone_book)
for i in range(1, n):
m = len(phone_book[i-1])
if phone_book[i-1] == phone_book[i][:m]:
answer = False
break
return answer
from collections import defaultdict
import operator
def solution(genres, plays):
g = defaultdict(int)
arr = defaultdict(list)
for i in range(len(genres)):
g[genres[i]] += plays[i]
arr[genres[i]].append((plays[i], i))
g = sorted(g.items(), reverse=True, key=operator.itemgetter(1))
answer = []
for i in g:
arr[i[0]].sort(key = lambda x : (-x[0], x[1]))
print(arr[i[0]])
answer.append(arr[i[0]][0][1])
if len(arr[i[0]]) >= 2:
answer.append(arr[i[0]][1][1])
return answer