Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 논리 연산
- string유형
- 프로그래머스 배열만들기4
- C언어 스택 연산
- IPv4 주소체계
- const l-value참조자
- 입출력 관리자
- r-value참조자
- C언어 덱
- 값/참조/주소에 의한 전달
- 회전 및 자리 이동 연산
- 원형 연결 구조 연결된 큐
- C언어 계산기 프로그램
- 네트워크 결합
- auto 키워드
- 범위 기반 for문
- LAN의 분류
- 문자형 배열
- 프로그래머스 푸드 파이트 대회
- const화
- 알고리즘 조건
- c언어 괄호검사
- 유형 변환
- 운영체제 기능
- getline()함수
- 백준 파이썬
- 괄호 검사 프로그램
- l-value참조자
- 주기억장치
- 문제해결 단계
Archives
- Today
- Total
chyam
[백준] 1976번,python - 여행 가자 본문

https://www.acmicpc.net/problem/1976
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
m = int(input())
graph = [[] for _ in range(n+1)]
for i in range(n):
tmp = list(map(int,input().split()))
for j in range(n):
if tmp[j] == 1:
graph[i+1].append(j+1)
travel = list(map(int,input().split()))
visited = [False] * (n+1) # 도시에 방문했는지
def bfs(travel):
queue = deque([travel[0]])
visited[travel[0]] = True
while queue:
t = queue.popleft()
for i in graph[t]:
if not visited[i]: # 방문안한곳 가기
queue.append((i))
visited[i] = True
bfs(travel)
# 여행 계획에 있는 도시들 다 방문했는가
if all(visited[city] for city in travel):
print("YES")
else:
print("NO")'백준' 카테고리의 다른 글
| [백준] 2579번,python - 계단 오르기 (0) | 2025.10.30 |
|---|---|
| [백준] 5430번,python - AC (0) | 2025.09.25 |
| [백준] 14940번,python - 쉬운 최단거리 (0) | 2025.09.23 |
| [백준] 2178번, python - 미로 탐색 (0) | 2025.09.22 |
| [백준] 2559번,python - 수열 (0) | 2025.09.19 |