-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoteventree.cpp
More file actions
67 lines (64 loc) · 1.56 KB
/
Copy pathnoteventree.cpp
File metadata and controls
67 lines (64 loc) · 1.56 KB
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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
/*
void findDelEdg(int v, int e, std::map<int, std::vector<int>>& adjmap) {
bool done = false;
while(!done) {
}
}
*/
int countAllChild(vector <int> *v , int *childrens , int offset)
{
int totalSize = 0;
if(v[offset].size() == 0)
childrens[offset] = 1;
else if(0 == childrens[offset])
{
for(int i = 0; i < v[offset].size() ; i++)
{
totalSize += countAllChild(v,childrens,v[offset][i]);
}
}
childrens[offset] = totalSize + 1;
return childrens[offset];
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int vertices, edges;
int returnValue = 0;
cin >> vertices >> edges;
//std::map<int, std::vector<int>> adjmap;
vector<int> childVec[vertices];
int childs[vertices];
for(int i =0; i<vertices; i++)
childs[i] = 0;
for(int it=0; it < vertices; it++) {
int v1, v2;
cin >> v1 >> v2;
v1--; v2--;
childVec[v2].push_back(v1);
/*
if(adjmap.count(s)==0) {
adjmap[s] = std::vector<int>({d});
}
else
adjmap[s] = adjmap[s].push_back(d);
*/
}
//findDelEdg(vertices, edges, adjmap);
countAllChild(childVec, childs, 0);
for(int i = 1; i < vertices; i++)
{
if((childs[i])%2 == 0)
{
returnValue++;
}
}
cout<<returnValue<<endl;
return true;
}