[백준 4256번] 트리 (Python3)
import sys input = sys.stdin.readline from collections import deque def makepost(pstart,pend,istart,iend): if pstart>pend: return parent = preorder[pstart] postorder.appendleft(parent) if pstart == pend: return I = Index[parent]-istart makepost(pstart+I+1,pend,istart+I+1,iend) makepost(pstart+1,pstart+I,istart,istart+I-1) T = int(input()) for _ in range(T): N = int(input()) preorder = [*map(int,..
[백준 11657번] 타임머신 (Python3)
import sys input = sys.stdin.readline INF = 10**9 def BF(): DP = [INF]*N DP[0] = 0 for i in range(N): for x,y,w in graph: if DP[x] == INF: continue if DP[y] > DP[x]+w: DP[y] = DP[x]+w if i == N-1: return False return DP N,M = map(int,input().split()) graph = [] for i in range(M): x,y,w = map(int,input().split()) graph.append((x-1,y-1,w)) result = BF() if result: for i in range(1,N): if result[i]..