Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- unordered_map<int, vector<int>> graph;
- vector<bool> visited(100, false);
- int children[100]{ 0 };
- int countChildren(int a) {
- visited[a] = true;
- if (graph[a].empty()) {
- return 0;
- }
- for (int child : graph[a]) {
- if(!visited[child])
- children[a] += countChildren(child) + 1;
- }
- return children[a];
- }
- int main() {
- int v, e, a, b;
- cin >> v >> e;
- for (int i = 0; i < e; i++) {
- cin >> a >> b;
- graph[a].push_back(b);
- graph[b].push_back(a);
- }
- countChildren(1);
- int count = 0;
- for (int i = 0; i < v; i++) {
- if (children[i] % 2 == 1)
- count++;
- }
- cout << count - 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment