-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaek_1260.py
More file actions
50 lines (40 loc) · 821 Bytes
/
Baek_1260.py
File metadata and controls
50 lines (40 loc) · 821 Bytes
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
44
45
46
47
48
49
50
import sys
n, m, v = map(int, sys.stdin.readline().split())
c = [[0]*(n+1) for i in range(n+1)]
df = []
bf = []
for i in range(m):
a, b = map(int, sys.stdin.readline().split())
c[a][b] += 1
c[b][a] += 1
d = []
e = [v]
while e:
u = e[0]
del e[0]
if u not in d:
d.append(u)
for i in range(1,n+1):
if c[u][i] > 0:
if i not in d and i not in e:
e.append(i)
#print(d)
h = []
e = [v]
while e:
u = e[0]
del e[0]
if u not in h:
h.append(u)
k = []
for i in range(1,n+1):
if c[u][i] > 0:
if i not in h:
k.append(i)
k.extend(e)
e = k
for i in h:
print(i, end = " ")
print()
for i in d:
print(i, end = " ")