-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cu
48 lines (36 loc) · 801 Bytes
/
example.cu
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
#include <cstdint>
#include <iostream>
#include "graph.hpp"
#include "mst.hpp"
using namespace std;
int main(int argc, char **argv) {
while (true) {
uint32_t vertices;
cin >> vertices;
if (vertices == 0)
break;
CSRGraphBuilder builder{vertices};
uint32_t edges;
cin >> edges;
for (uint32_t i = 0; i < edges; i++) {
uint32_t u, v, w;
cin >> u >> v >> w;
// map 0..1
u--;
v--;
builder.addEdge(u, v, w);
builder.addEdge(v, u, w);
}
auto graph = builder.build();
auto *r = MST(graph);
uint32_t mstPathCost = 0;
for (uint32_t i = 0; i < graph.E; i++) {
if (r[i] == true) {
mstPathCost += graph.W[i];
}
}
cout << mstPathCost << '\n';
cudaFree(r);
}
return 0;
}