-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_22860.py
More file actions
60 lines (49 loc) · 1.43 KB
/
Copy pathbj_22860.py
File metadata and controls
60 lines (49 loc) · 1.43 KB
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
58
59
60
import sys
from collections import deque
sys.stdin = open('bj_22860_in.txt', 'r')
input = sys.stdin.readline
folder_cnt, file_cnt = map(int, input().strip().split())
# print(folder_cnt, file_cnt)
d= dict()
for _ in range(folder_cnt + file_cnt):
p, f, c = input().strip().split()# p: 상위 폴더명, f: 폴더 or file명, c: 폴더여부(1:폴더, 0:파일)
# print(p, f, c)
if d.get(p): #존재
d[p].append((f, c))
else: #미존재
d[p] = [(f, c)]
# print(d)
q = int(input().strip())
# print(q)
for _ in range(q): #쿼리 질의
cmd = input().strip()
name = set()
cnt = 0
for i in reversed(range(len(cmd))):
if cmd[i] == '/':
break
else:
idx = i
# print(idx)
target = cmd[idx:] #타겟 폴더 이름
# print(target)
if d.get(target): #존재
q = deque(d[target])
while q: #q가 존재하면 계속 실행
# print(q)
e = q.popleft()
f = e[0]
c = e[1]
# print(f)
# 원소의 파일 여부 체크
if c == '1': #폴더면 q에 삽입
if d.get(f): #딕셔너리에 존재하면
# print(d.get(f))
for x in d[f]:
q.append(x)
else: #파일이면 set에 삽입
name.add(f)
cnt += 1
else:
pass
print(len(name), cnt)