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

https://www.acmicpc.net/problem/1005
from collections import deque
import sys
input = sys.stdin.readline
t = int(input())
def solution():
n, k = map(int,input().split())
time = list(map(int,input().split()))
graph = [[] for _ in range(n+1)]
indegree = [0]*(n+1)
dp = [0]*(n+1) # 해당 건물까지 걸리는 최대 시간
for _ in range(k):
x, y = map(int,input().split())
graph[x].append(y)
indegree[y] += 1
target = int(input())
queue = deque()
# 진입차수 0 초기화
for i in range(1, n+1):
if indegree[i] == 0:
queue.append(i)
dp[i] = time[i-1]
while queue:
now = queue.popleft()
for next_node in graph[now]:
indegree[next_node] -= 1
dp[next_node] = max(dp[next_node], dp[now] + time[next_node-1])
if indegree[next_node] == 0:
queue.append(next_node)
return dp[target]
for _ in range(t):
print(solution())'백준' 카테고리의 다른 글
| [백준] 9663번, python - N-Queen (0) | 2026.03.06 |
|---|---|
| [백준] 1759번, python - 암호 만들기 (1) | 2026.03.05 |
| [백준] 2252번, python - 줄 세우기 (위상 정렬) (0) | 2026.03.02 |
| [백준] 2294번,python - 동전 2 (0) | 2026.02.11 |
| [백준] 1922번, python - 네트워크 연결(Union-Find) (0) | 2026.01.26 |
