-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC982.cpp
More file actions
67 lines (54 loc) · 826 Bytes
/
Copy pathC982.cpp
File metadata and controls
67 lines (54 loc) · 826 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
vector<int> adj[100005];
bool visited[100005];
vector<int> children[100005];
int size[100005];
int dfs(int u, int p)
{
size[u] = 1;
for(int v: adj[u])
{
if(v != p)
{
children[u].pb(v);
size[u] += dfs(v, u);
}
}
return size[u];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin>>n;
for(int i = 1; i < n; i++)
{
int u, v; cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
if(n % 2 == 1)
{
cout << -1 << '\n';
return 0;
}
//visited[1] = true;
dfs(1, 0);
int ans = 0;
for(int u = 1; u < n+1; u++)
{
for(int v : children[u])
{
if(size[v] %2 == 0)
{
ans++;
}
}
}
cout << ans << '\n';
return 0;
}