Created
May 7, 2016 23:25
-
-
Save Abdujabbar/b5ffd07d413e340867c2bca9fa0b7df0 to your computer and use it in GitHub Desktop.
STEPIC
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
import json | |
import operator | |
def dfs(graph, start): | |
visited, stack = set(), [start] | |
while stack: | |
vertex = stack.pop() | |
if vertex not in visited: | |
visited.add(vertex) | |
stack.extend(graph[vertex] - visited) | |
return visited | |
_input = input() | |
j = json.loads(_input) | |
_dict = dict() | |
for i in j: | |
_dict[i['name']] = set() | |
for i in j: | |
for item in i['parents']: | |
_dict[item].add(i['name']) | |
__dict = sorted(_dict, key=operator.itemgetter(0)) | |
for v in __dict: | |
print(v + " : " + str(len(dfs(_dict, v)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment