섬 연결하기
[3] 섬 연결하기
#include #include #include using namespace std; vector vIsland(100); bool Cmp(vector a, vector b) { return a[2] < b[2]; } int FindParent(int idx) { if (vIsland[idx] != idx) vIsland[idx] = FindParent(vIsland[idx]); return vIsland[idx]; } int solution(int n, vector costs) { int answer = 0; sort(costs.begin(), costs.end(), Cmp); for (int i = 0; i < n; i++) vIsland[i] = i; for (int i = 0; i < costs...