목록Union-Find (1)
레야몬
[C++] 1197번 최소 스패닝 트리 - 최소 스패닝 트리, Union-Find
#include #include #include #include #define MAX_VERTEX 10001 #define MAX_TRUNK 100001 using namespace std; typedef long long int lld; int V, E; //정점의 개수 V, 간선의 개수 E vector map[MAX_TRUNK]; //정점의 연결관계 표시 맵 int root[MAX_VERTEX]; //union-find 용 lld w; //가중치의 합 int find(int x) //x의 루트 찾기 { if(root[x]==x) return x; else return root[x]=find(root[x]); } void _union(int x, int y) { x=find(x); y=find(y); ..
알고리즘/백준
2022. 9. 7. 19:30