[백준 3111번] 검열 (Python3)
from collections import * def delete(T,stack,A,p): while T: if p: stack.append(T.pop()) else: stack.append(T.popleft()) if stack[-1]==A[-1]: if stack[-N:]==A: for _ in range(N): stack.pop() return 1 return A = [*input()]; A2 = [*reversed(A)]; N = len(A) T = deque([*input()]) front = []; back = [] while delete(T,front,A,0) and delete(T,back,A2,1): continue while delete(back,front,A,1): continue p..
[백준 10217번] KCM Travel (Python3)
import sys input = sys.stdin.readline from heapq import * for _ in range(int(input())): N,M,K = map(int,input().split()) graph = [[] for i in range(N)] for _ in range(K): a,b,c,d = map(int,input().split()) graph[a-1].append((b-1,c,d)) hq = [(0,0,0)]; distance = [1e9]*N; DP = [1e9]*N while hq: c,now,d = heappop(hq) if DP[now] c+c1: DP[next..
[백준 16118번] 달빛 여우 (Python3)
import sys input = sys.stdin.readline from heapq import * N,M = map(int,input().split()) graph = [[] for i in range(N)] for _ in range(M): a,b,c = map(int,input().split()) graph[a-1].append((b-1,c*2)) graph[b-1].append((a-1,c*2)) fox = [1e12]*N; hq = [(0,0)] while hq: w,now = heappop(hq) if fox[now] w+w1: fox[next] = w+w1 heappush(hq,(w+w1,..