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;
- unordered_map<int, int> countNodes;
- bool visited[100]{ false };
- void dfs(int v) {
- visited[v] = true;
- auto neighbours = graph[v];
- for (int i = 0; i < neighbours.size(); i++) {
- if (!visited[neighbours[i]]) {
- dfs(neighbours[i]);
- countNodes[v] += countNodes[neighbours[i]] + 1;
- }
- }
- }
- int main() {
- int n, e, a, b;
- cin >> n >> e;
- for (int i = 0; i < e; i++) {
- cin >> a >> b;
- graph[a].push_back(b);
- graph[b].push_back(a);
- }
- int res = 0;
- dfs(1);
- for (auto i : countNodes) {
- if (i.second % 2 != 0)
- res++;
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment