-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1041.cpp
More file actions
49 lines (49 loc) · 769 Bytes
/
Copy pathP1041.cpp
File metadata and controls
49 lines (49 loc) · 769 Bytes
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
#include <iostream>
#include <stdio.h>
using namespace std;
int n, p, f[301], head[301], edptr= 1;
int tmpx, tmpy;
struct edge {
int to, nexty;
} eds[1001];
void add(int a, int b) {
eds[edptr].to= b, eds[edptr].nexty= head[a];
head[a]= edptr++;
return;
}
void dp(int nown, int fa) {
int sons= 0, maxs= 0, tot= 0;
for(int i= head[nown], to; i; i= eds[i].nexty) {
to= eds[i].to;
if(to == fa) continue;
dp(to, nown);
++sons, maxs= max(maxs, f[to]), tot+= f[to];
}
if(sons >= 2) f[nown]= tot - maxs + sons - 1;
return;
}
int main() {
cin >> n >> p;
for(int i= 0; i < p; i++) {
cin >> tmpx >> tmpy;
add(tmpx, tmpy), add(tmpy, tmpx);
}
dp(1, -1);
cout << f[1] + 1 << endl;
return 0;
}
/*
13 12
1 2
1 3
1 4
1 5
1 6
6 7
6 8
6 9
2 10
3 11
4 12
5 13
*/