#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int kruskal(int sizes, vector<vector<int>> c) {
vector<int> v;
sort(c.begin(), c.end());
int answer = 0;
v.push_back(c[0][0]);
while (v.size() < sizes) {
int temp = 987654321;
int index = 0;
for (int i = 0; i < c.size(); i++) {
if(count(v.begin(),v.end(),c[i][0]) == 1 && count(v.begin(),v.end(),c[i][1])==1)
continue;
else {
if (count(v.begin(), v.end(), c[i][0]) == 1 || count(v.begin(), v.end(), c[i][1])==1) {
if (temp > c[i][2]) {
temp = c[i][2];
index = i;
}
}
}
}
answer += temp;
v.push_back(c[index][0]);
v.push_back(c[index][1]);
c.erase(c.begin() + index);
v.erase(unique(v.begin(), v.end()), v.end());
}
return answer;
}
int solution(int n, vector<vector<int>> costs) {
return kruskal(n,costs);
}
프로그래머스