-
Notifications
You must be signed in to change notification settings - Fork 0
/
boj_14675_graph.py
57 lines (48 loc) · 1.44 KB
/
boj_14675_graph.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
tree = [[] for _ in range(n + 1)]
lines = []
for _ in range(n - 1):
f,t = list(map(int, input().rstrip().split(" ")))
tree[f].append(t)
lines.append([f,t])
q_n = int(input())
def bfs_point(start, cutted_point):
total_length = 1
visited = [False for _ in range(n + 1)]
que = deque([])
que.append(start)
visited[start] = True
while len(que) != 0:
cur = que.popleft()
for connected_point in tree[cur]:
if connected_point == cutted_point:
continue
if visited[connected_point] == False:
que.append(connected_point)
total_length += 1
return total_length
def bfs_line(start, cutted_line):
total_length = 1
visited = [False for _ in range(n + 1)]
que = deque([])
que.append(start)
visited[start] = True
while len(que) != 0:
cur = que.popleft()
for connected_point in tree[cur]:
if visited[connected_point] == False:
que.append(connected_point)
total_length += 1
return total_length
res = []
for _ in range(q_n):
q, point = list(map(int, input().rstrip().split(" ")))
if q == 1:
if len(tree) != bfs_point(1, point):
res.append("no")
else:
res.append("yes")
else: