Skip to content

Instantly share code, notes, and snippets.

@IKKO-Ohta
Created July 5, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IKKO-Ohta/c22dcc7f52f38df7f7d1be5797b1ae61 to your computer and use it in GitHub Desktop.
Save IKKO-Ohta/c22dcc7f52f38df7f7d1be5797b1ae61 to your computer and use it in GitHub Desktop.
# coding: utf-8
nums=[int(x) for x in input().split()]
V,E = nums[0],nums[1]
graph = {x:[] for x in range(V)}
for i in range(E):
nums=[int(x) for x in input().split()]
a,b = nums[0]-1,nums[1]-1
graph[a].append(b)
graph[b].append(a)
def solve(person):
"""
ある人について、”友達の友達”を調べる
"""
friends = graph[person]
fof = ()
for friend in friends:
for ff in graph[friend]:
fof.add(ff)
[ff.remove(friend) for friend in friends]
ff.remove(person)
return len(ff)
if __name__ == '__main__':
for p in graph.keys():
ans = solve(int(p))
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment