-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzn_theuler.cpp
68 lines (55 loc) · 1.31 KB
/
zn_theuler.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
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
#include <utility>
#include <list>
#include <cstdio>
using namespace std;
int const maxVertexNum = 102;
int n;
int m;
pair<int, int> coords[maxVertexNum];
list<int> edges[maxVertexNum];
int componentNumber = 0;
int componentEdgeDoubleNumber[maxVertexNum];
int componentVertexNumber[maxVertexNum];
bool used[maxVertexNum];
void dfs(int v) {
if (used[v])
return;
used[v] = true;
componentVertexNumber[componentNumber]++;
componentEdgeDoubleNumber[componentNumber] += edges[v].size();
for (list<int>::iterator it = edges[v].begin(); it != edges[v].end(); it++) {
int x = *it;
dfs(x);
}
}
int main() {
FILE* in = fopen("theuler.in", "r");
fscanf(in, "%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
//coords reading
fscanf(in, "%d %d", &coords[i].first, &coords[i].second);
}
for (int i = 0; i < m; i++) {
//edges reading
int start;
int end;
fscanf(in, "%d %d", &start, &end);
edges[start].push_back(end);
edges[end].push_back(start);
}
fclose(in);
for (int i = 1; i <= n; i++) {
if (!used[i]) {
dfs(i);
componentNumber++;
}
}
int result = 1 - componentNumber;
for (int i = 0; i < componentNumber; i++) {
result += 2 - componentVertexNumber[i] + componentEdgeDoubleNumber[i] / 2;
}
FILE* out = fopen("theuler.out", "w");
fprintf(out, "%d", result);
fclose(out);
return 0;
}