6using PII = std::pair<int, int>;
8int prim(
int x,
const std::vector<std::vector<PII> > &
graph) {
10 std::priority_queue<PII, std::vector<PII>, std::greater<PII> > Q;
11 std::vector<bool> marked(
graph.size(),
false);
14 Q.push(std::make_pair(0, x));
21 if (marked[x] ==
true) {
24 minimum_cost += p.first;
26 for (
const PII &neighbor :
graph[x]) {
27 int y = neighbor.second;
28 if (marked[y] ==
false) {
37 int nodes = 0, edges = 0;
38 std::cin >> nodes >> edges;
39 if (nodes == 0 || edges == 0) {
43 std::vector<std::vector<PII> >
graph(nodes);
46 for (
int i = 0; i < edges; ++i) {
47 int x = 0, y = 0, weight = 0;
48 std::cin >> x >> y >> weight;
49 graph[x].push_back(std::make_pair(weight, y));
50 graph[y].push_back(std::make_pair(weight, x));
54 int minimum_cost = prim(1,
graph);
55 std::cout << minimum_cost << std::endl;