-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path79.py
43 lines (38 loc) · 868 Bytes
/
79.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
# build graph
graph = {}
for line in sys.stdin:
a = map(int, list(line.strip()))
for i in enumerate(a):
for j in enumerate(a):
if i[0] < j[0]:
if i[1] not in graph:
graph[i[1]] = set([j[1]])
else:
graph[i[1]].add(j[1])
# find source
seq = []
for i in graph.keys():
mark = True
for j in graph.values():
if i in j:
mark = False
if mark:
print i
seq.append(i)
# continue
for i in seq:
print i
if i not in graph:
break
for j in graph[i]:
mark = True
for k in graph.items():
if k[0] not in seq:
if j in k[1]:
mark = False
if mark and j not in seq:
seq.append(j)
break
print seq
print seq