Created
July 5, 2017 13:22
-
-
Save IKKO-Ohta/c22dcc7f52f38df7f7d1be5797b1ae61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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