Skip to content

Commit 6eaea3f

Browse files
Merge pull request #692 from gmlrude/main
[박희경] 105차 라이브 코테 제출
2 parents 285dc28 + 452b5b1 commit 6eaea3f

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
7+
# 도시 개수, 도로 개수, 거리 정보, 출발 도시
8+
n, m, k, x = map(int, input().split())
9+
graph = [[] for _ in range(n + 1)]
10+
11+
for _ in range(m):
12+
a, b = map(int, input().split())
13+
graph[a].append(b)
14+
15+
visited = [0] * (n + 1)
16+
visited[x] = 1
17+
result = []
18+
q = deque(([(x, 0)]))
19+
while q:
20+
x, cnt = q.popleft()
21+
if cnt == k:
22+
result.append(x)
23+
for nei in graph[x]:
24+
if not visited[nei]:
25+
visited[nei] = 1
26+
q.append((nei, cnt + 1))
27+
28+
if not result:
29+
print(-1)
30+
else:
31+
for res in sorted(result):
32+
print(res)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
alpha = [chr(i) for i in range(ord('a'),ord('z')+1)]
6+
arr = [[0] * 26 for _ in range(26)]
7+
8+
9+
n = int(input())
10+
for _ in range(n):
11+
i, _, j = map(str, input().split())
12+
arr[alpha.index(i)][alpha.index(j)] = 1
13+
14+
for k in range(26):
15+
for i in range(26):
16+
for j in range(26):
17+
if i == j: continue
18+
if arr[i][k] == 1 and arr[k][j] == 1:
19+
arr[i][j] = 1
20+
21+
22+
m = int(input())
23+
for _ in range(m):
24+
i, _, j = map(str, input().split())
25+
if arr[alpha.index(i)][alpha.index(j)] == 1:
26+
print('T')
27+
else:
28+
print('F')
29+
30+
31+
"""
32+
3
33+
a is b
34+
b is c
35+
c is d
36+
3
37+
a is d
38+
a is c
39+
d is a
40+
"""
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def solution(order):
2+
i = 0
3+
stack = []
4+
5+
for box in range(1, len(order) + 1):
6+
if box == order[i]:
7+
i += 1
8+
else:
9+
stack.append(box)
10+
while stack and stack[-1] == order[i]:
11+
stack.pop()
12+
i += 1
13+
14+
return i

0 commit comments

Comments
 (0)