코드#include #include #include using namespace std;int n,m,lst[100003],a,b,c,res,mn;vector> v;int find(int x) { if(x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if(x > y) lst[x] = y; else lst[y] = x;}int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for(int i = 1; i > a >> b >> c; v..
1647번
코드 # 크루스칼 알고리즘 이용 import sys input = sys.stdin.readline def find(a,lst): if a != lst[a]: lst[a] = find(lst[a], lst) return lst[a] def union(a,b,lst): a = find(a,lst) b = find(b,lst) if a < b: lst[b] = a else: lst[a] = b n, m = map(int, input().split()) parent = [i for i in range(n+1)] edge = [] for _ in range(m): a,b,c = map(int, input().split()) edge.append((c,a,b)) edge.sort(key=lambda x: x[0]..