본문 바로가기

분류 전체보기

(402)
[백준 3640번] 제독 (Python3) import sys,collections def input(): return map(int,sys.stdin.readline().split()) def SPFA(): DP = [1e9]*K; DP[3] = 0 dq = collections.deque([3]); inq = [0]*K parent = [0]*K while dq: now = dq.popleft() inq[now] = 0 for next in graph[now]: w,c = graph[now][next] if c-flow[now][next] and DP[next]>(w1:=DP[now]+w): DP[next] = w1; parent[next] = now if not inq[next]: dq.append(next); inq[next] = 1 re..
[백준 3683번] 고양이와 개 (Python3) import sys input = sys.stdin.readline def DFS(i): if visited[i]: return visited[i] = 1 for j in graph[i]: if match[j]C: graph[n].append(y) else: graph[y].append(n) match = [-1]*N for i in range(N): visited = [0]*N DFS(i) print(match.count(-1)) 이분매칭 + 콰닉의 정리 응용문제 이분매칭 문제임을 알고 문제를 풀었는데도 왜 이분매칭인지 파악하기 쉽지 않은 문제였다. 시청자를 고양이를 좋아하는 집단과 개를 좋아하는 집단, 두 집단으로 분리하는것이 핵심이다. 풀이를 설명하면, 1. 고양이파 - 개파의 이분그래프를 그린다...
[백준 14572번] 스터디 그룹 (Python3) import sys def input(): return [*map(int,sys.stdin.readline().split())] def update(i,v,x): global kn,un,cnt cnt += x for k in study[i][1]: if known[k]==v: kn += x known[k] += x for k in study[i][2]: if unknown[k]==v: un += x unknown[k] += x def solve(): j = result = 0 for i in range(N): for j in range(j,N): if study[i][0]-study[j][0]
[백준 2367번] 파티 (Python3) import sys from collections import * def input(): return [*map(int,sys.stdin.readline().split())] def BFS(): dq = deque([(0,1e9)]) visited = [-1]*K while dq: now,f = dq.popleft() for next in graph[now]: if visited[next]
[백준 11407번] 책 구매하기 3 (Python3) import sys from collections import * def input(): return [*map(int,sys.stdin.readline().split())] def SPFA(): DP = [1e9]*K; DP[0] = 0 dq = deque([0]); inq = [0]*K; parent = [0]*K while dq: now = dq.popleft() inq[now] = 0 for next in adj[now]: c,w = graph[now][next]; w1 = DP[now]+w if c-flow[now][next] and w1
[백준 11405번] 책 구매하기 (Python3) import sys from collections import * def input(): return [*map(int,sys.stdin.readline().split())] def SPFA(): DP = [1e9]*K; DP[0] = 0 dq = deque([0]); inq = [0]*K; parent = [0]*K while dq: now = dq.popleft() inq[now] = 0 for next in adj[now]: c,w = graph[now][next]; w1 = DP[now]+w if c-flow[now][next] and w1
[백준 1420번] 학교 가지마! (Python3) from collections import * dy = [1,-1,0,0]; dx = [0,0,1,-1] def BFS(): visited = [-1]*N*M*2; visited[K+N*M] = K dq = deque([K+N*M]) while dq: now = dq.popleft() if now==H: return visited for next,c in graph[now]: if visited[next]y1>=0 and M>x1>=0 and board[y1][x1]!="#": graph[y1*M+x1+N*M].append((y*M+x,1)) graph[y*M+x].append((y1*M+x1+N*M,0)) flow = [{i:0 for i,c in graph[n]} for n in range(N*M*2..
[백준 14750번] Jerry and Tom (Python3) import sys def input(): return [*map(int,sys.stdin.readline().split())] def ccw(x1,y1,x2,y2,x,y): return (x2-x1)*(y-y1)-(y2-y1)*(x-x1) def crossed(x1,y1,x2,y2,x3,y3,x4,y4): ccw12,ccw34 = ccw(x1,y1,x2,y2,x3,y3)*ccw(x1,y1,x2,y2,x4,y4),ccw(x3,y3,x4,y4,x1,y1)*ccw(x3,y3,x4,y4,x2,y2) if ccw12==0 and ccw34==0: if min(x1,x2)