A61 - Adjacent Vertices
https://atcoder.jp/contests/tessoku-book/tasks/tessoku_book_bi
提出
code: python
n, m = map(int, input().split())
ab = list(map(int, input().split())) for _ in range(m)
g = {}
for i in range(1, n+1):
gi = set()
for a, b in ab:
gb.add(a)
ga.add(b)
print(g)
解答
code: python
N, M = map(int, input().split())
edges = list(map(int, input().split())) for i in range(M)
# 隣接リストの作成
G = list() for i in range(N + 1)
for a, b in edges:
Ga.append(b)
Gb.append(a)
# 出力
for i in range(1, N + 1):
output = ''
output += str(i)
output += ': {'
output += ', '.join(map(str, Gi)) # 例えば Gi = { 2, 7, 5 } のとき、ここで "2, 7, 5" という文字列が output の後ろに連結される
output += '}'
print(output)