알고리즘 문제 풀이/이코테 60

[이코테] CH10 그래프 이론 실전문제 44번 행성 터널

https://www.acmicpc.net/problem/2887 문제 2887번: 행성 터널 첫째 줄에 행성의 개수 N이 주어진다. (1 ≤ N ≤ 100,000) 다음 N개 줄에는 각 행성의 x, y, z좌표가 주어진다. 좌표는 -109보다 크거나 같고, 109보다 작거나 같은 정수이다. 한 위치에 행성이 두 개 이 www.acmicpc.net 때는 2040년, 이민혁은 우주에 자신만의 왕국을 만들었다. 왕국은 N개의 행성으로 이루어져 있다. 민혁이는 이 행성을 효율적으로 지배하기 위해서 행성을 연결하는 터널을 만들려고 한다. 행성은 3차원 좌표위의 한 점으로 생각하면 된다. 두 행성 A(xA, yA, zA)와 B(xB, yB, zB)를 터널로 연결할 때 드는 비용은 min(|xA-xB|, |yA-y..

[이코테] CH10 그래프 이론 실전문제 43번 어두운 길

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def find_parent(parent,x): if parent[x]!=x: parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,a,b): a = find_parent(parent,a) b = find_parent(pare..

[이코테] CH10 그래프 이론 실전문제 42번 탑승구

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def find_parent(parent,x): if parent[x]!=x: parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,a,b): a = find_parent(parent,a) b = find_parent(pare..

[이코테] CH10 그래프 이론 실전문제 41번 여행 계획

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def find_parent(parent,x): if parent[x]!=x: parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,a,b): a = find_parent(parent,a) b = find_parent(pare..

[이코테] CH10 그래프 이론 실전문제 4번 커리큘럼

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def topologysort(index): q = deque() for i in range(N): if indegree2[i] == 0: q.append(i) # 문제 없음 , 처음엔 1이 큐에 기본적으로 들어가서 시작하겠지 while q: now = q.popleft() for i in graph[now]: if i..

[이코테] CH10 그래프 이론 실전문제 3번 도시 분할 계획

https://www.acmicpc.net/problem/1647 1647번: 도시 분할 계획 첫째 줄에 집의 개수 N, 길의 개수 M이 주어진다. N은 2이상 100,000이하인 정수이고, M은 1이상 1,000,000이하인 정수이다. 그 다음 줄부터 M줄에 걸쳐 길의 정보가 A B C 세 개의 정수로 주어지는데 A번 www.acmicpc.net 문제 동물원에서 막 탈출한 원숭이 한 마리가 세상구경을 하고 있다. 그러다가 평화로운 마을에 가게 되었는데, 그곳에서는 알 수 없는 일이 벌어지고 있었다. 마을은 N개의 집과 그 집들을 연결하는 M개의 길로 이루어져 있다. 길은 어느 방향으로든지 다닐 수 있는 편리한 길이다. 그리고 각 길마다 길을 유지하는데 드는 유지비가 있다. 임의의 두 집 사이에 경로가 ..

[이코테] CH10 그래프 이론 실전문제 2번 팀 결성

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def find_parent(parent,x): if parent[x]!=x: parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,x,y): x = find_parent(parent,x) y = find_parent(pare..

[이코테] CH10 그래프 이론 크루스칼 알고리즘 기본 코드

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def find_parent(parent,x): if parent[x]!=x: parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,a,b): a = find_parent(parent,a) b = find_parent(pare..

[이코테] CH09 최단경로 실전문제 40번 숨바꼭질

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def findMax(start): q = [] heapq.heappush(q,(0,start)) distance[start] = 0 while q: dist,now = heapq.heappop(q) # now는 노드 번호고 dist는 비용 if distance[now] < dist: continue for i in g..

[이코테] CH09 최단경로 실전문제 39번 화성 탐사

import sys # sys.stdin.readline() from collections import deque sys.setrecursionlimit(100000000) import heapq import copy import itertools from itertools import combinations from itertools import permutations INF = 1e9 def findMin(): dx = [-1,0,1,0] dy = [0,1,0,-1] # 상하좌우 움직일 수 있으므로!! q = [] heapq.heappush(q,(graph[0][0],0,0)) # 비용, row, col (start) while q: dist,row,col = heapq.heappop(q) # 힙에서..