개발자 톡
연습문제 톡
[HSAT 6회 정기 코딩 인증평가 기출] 출퇴근길
[HSAT 6회][level3] 출퇴근길
- 등록일
- 2023-10-05 02:53:52
- 조회수
- 881
- 작성자
- rlaehrud57
아래 경우에 오답 케이스를 알 수 있을까요?
어느 부분이 잘못됐는지 못찾겠네요..
import sys
from collections import deque
n, m = map(int, input().split())
adj = [[] for _ in range(n + 1)]
adj_reverse = [[] for _ in range(n + 1)]
for _ in range(m) :
a, b = map(int, input().split())
adj[a].append(b)
adj_reverse[b].append(a)
S, T = map(int, input().split())
visited_1 = [0] * (n + 1)
visited_1_R = [0] * (n + 1)
visited_2 = [0] * (n + 1)
visited_2_R = [0] * (n + 1)
def BFS(start, end, visited) :
queue = deque()
queue.append(start)
visited[start] = 1
while queue :
now = queue.popleft()
if now == end :
continue
for neighbor in adj[now] :
if not visited[neighbor] :
visited[neighbor] = 1
queue.append(neighbor)
BFS(S, T, visited_1)
BFS(S, T, visited_1_R)
BFS(T, S, visited_2)
BFS(T, S, visited_2_R)
visited_1[S] = visited_1[T] = 0
visited_1_R[S] = visited_1_R[T] = 0
visited_2[S] = visited_2[T] = 0
visited_2_R[S] = visited_2_R[T] = 0
cnt = 0
for i in range(1, n + 1) :
if visited_1[i] and visited_1_R[i] and visited_2[i] and visited_2_R[i] :
cnt += 1
print(cnt)
#[hsat_6회_정기_코딩_인증평가_기출]_출퇴근길
#python
#bfs