-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10423.cpp
More file actions
77 lines (65 loc) · 1.26 KB
/
10423.cpp
File metadata and controls
77 lines (65 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int n,m,k;
class Edge{
public:
int s;
int e;
int cost;
Edge(int s, int e, int cost){
this->s = s;
this->e = e;
this->cost = cost;
}
bool operator<(Edge &edge){
return this->cost<edge.cost;
}
};
vector<Edge> v;
int parent[100001];
int getParent(int idx)
{
if(idx==parent[idx]) return idx;
else return parent[idx] = getParent(parent[idx]);
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b,c;
int ans = 0;
cin>>n>>m>>k;
for (int i = 1; i <= n; i++)
{
parent[i] = i;
}
for (int i = 0; i < k; i++)
{
/* code */
}
for (int i = 0; i < m; i++)
{
cin>>a>>b>>c;
v.push_back(Edge(a,b,c));
}
sort(v.begin(),v.end());
for(int i = 0; i < v.size(); i++)
{
int sp = getParent(v[i].s);
int ep = getParent(v[i].e);
int cost = v[i].cost;
if(sp!=ep)
{
ans = ans + cost;
if(sp>ep) parent[sp] = ep;
else parent[ep] = sp;
}
}
cout<<ans<<"\n";
return 0;
}