본문 바로가기

분류 전체보기

(402)
[백준 11400번] 단절선 (Python3) import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) def DFS(now,last): global id visited[now] = ID[now] = id for next in graph[now]: if next==last: continue if not visited[next]: id += 1 DFS(next,now) if ID[next]==visited[next]: result.append(sorted((now,next))) visited[now] = min(visited[now],visited[next]) N,M = map(int,input().split()) graph = [[] for i in range(N+1)] for _ in ..
[백준 1006번] 습격자 초라기 (Python3) def solve(i): DP = [[2*N]*(N+1) for i in range(4)]; DP[i][-1] = 0 for n in range(N): for i in range(4): DP[0][n] = min(DP[0][n],DP[i][n-1]+int(i&1==0)+int(i&2==0)) if enemy[0][n]+enemy[1][n]
[백준 12930번] 두 가중치 (Python3) from heapq import * def dij(): DP = [{} for i in range(N)] hq = [(0,0,0,1)] while hq: w1,w2,now,bit = heappop(hq) if w2!=0 and DP[now][w2]
[백준 25378번] 조약돌 (Python3) N = int(input()) rock = [*map(int,input().split())] DP = [0]*N for i in range(N): DP[i] = max(DP[i],DP[i-1]) x = rock[i] for j in range(i+1,N): x = rock[j]-x if x
[백준 17835번] 면접보는 승범이네 (Python3) import sys input = sys.stdin.readline from heapq import * N,M,K = map(int,input().split()) graph = [[] for i in range(N+1)] for _ in range(M): a,b,w = map(int,input().split()) graph[b].append((a,w)) data = [*map(int,input().split())] check = [0]*(N+1); hq = [] for a in data: check[a] = 1 for b,w in graph[a]: heappush(hq,(w,-b)) now,w = -1,0 for _ in range(N-K): while 1: w,now = heappop(hq) if ch..
[백준 22345번] 누적 거리 (Python3) import sys,bisect input = sys.stdin.readline N,Q = map(int,input().split()) town = [] for _ in range(N): a,x = map(int,input().split()) town.append((x,a)) town.sort() cnt = [-sum(town[i][1] for i in range(N))] for i in range(N): cnt.append(cnt[-1]+town[i][1]*2) prefix = [sum((town[i][0]-town[0][0])*town[i][1] for i in range(N))] for i in range(N-1): prefix.append(prefix[-1]+(town[i+1][0]-town[i]..
[백준 24505번] blobhyperthink (Python3) def update(i,v): while i
[백준 13555번] 증가하는 부분 수열 (Python3) def update(i,v): while i