-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
40 lines (32 loc) · 814 Bytes
/
main.cpp
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
#include <iostream>
#include "EdmondsMatching.hpp"
int main(int argc, char *argv[])
{
int n, m;
std::cin >> n >> m;
if (n % 2 == 1)
{
std::cout << "NO" << std::endl;
return 1;
}
EdmondsMatching matching(n);
for (int i = 0; i < m; i++)
{
int v1, v2, w;
std::cin >> v1 >> v2 >> w;
// Input is indexed from 1
matching.addEdge(v1 - 1, v2 - 1, w);
}
bool success = matching.findMinimumWeightMatching();
if (!success)
{
std::cout << "NO" << std::endl;
return 1;
}
int weight = matching.getMatchingWeight();
auto edges = matching.getMatchedEdges();
std::cout << weight << std::endl;
for (auto e: edges)
std::cout << e.first << " " << e.second << std::endl;
return 0;
}