[백준 바킹독] 0x09 - BFS 토마토(7576)
Introduction
크루스칼 알고리즘은 가장 적은 비용으로 모든 노드를 연결하기 위해 사용하는 알고리즘이다. 즉, 최소 비용 신장 트리를 만들기 위한 대표적인 알고리즘이라고 할 수 있다.
실행순서
import sys
input = sys.stdin.readline
V, E = map(int,input().split())
# 부모 테이블상에서, 부모를 자기 자신으로 초기화
# -> 독립된 노드라는 의미
parent = [0]*(V+1)
for i in range(1,V+1):
parent[i] = i
# 간선을 입력받아 cost를 기준으로 오름차순 정렬
edges = []
for _ in range(E):
A, B, C = map(int,input().split())
edges.append((C,A,B))
edges.sort()
## Union-Find Algorithm
# Find: 특정 원소가 속한 집합 찾기
def find_parent(parent, x):
if parent[x] != x:
parent[x] = find_parent(parent, parent[x])
return parent[x]
# Union: 두 원소가 속한 집합을 합치기
def union_parent(parent, a, b):
a = find_parent(parent, a)
b = find_parent(parent, b)
if a < b:
parent[b] = a
else:
parent[a] = b
result = 0
## Kruskal Algorithm
# cost가 낮은 순으로 정렬된 간선을 하나씩 확인
for edge in edges:
cost, a, b = edge
# 두 노드의 루트 노드가 서로 다르면 사이클이 발생하지 않는다.
if find_parent(parent,a) != find_parent(parent,b):
# 신장 트리 추가 및 사이클 태이블 갱신
union_parent(parent,a,b)
result += cost
print(result)
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
1167 트리의 지름
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Git 명령어를 사용한 하위 디렉토리 다운로드 Clone 할 로컬 저장소 생성
Introduction
# Fetch the submodule commits into the main repository git remote add submodule_origin git://url/to/submodule/origin git fetch submodule_origin
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Graph
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Spring Project
the page for java
가벼운 Base image를 사용
version: 3.0.0a10
WIDTH
version: 3.0.0a10
#include <iostream> #include <thread> #include <chrono> #include <mutex> #include <atomic> #include <string.h>
version: 3.0.0a10
https://cplusplus.com/reference/future/
Multithreading support was introduced in C++11.
how to costom github blog using jekyll
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...