Skip to content

Instantly share code, notes, and snippets.

@enzerr
Created September 15, 2023 20:05
Show Gist options
  • Save enzerr/41b6ef2019ba76ee17d238d609863816 to your computer and use it in GitHub Desktop.
Save enzerr/41b6ef2019ba76ee17d238d609863816 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
vector<int> adj[maxn];
bool pareado[maxn];
int ans=0;
void dfs(int u, int p) {
for (int v : adj[u]) if(v!=p) {
dfs(v, u);
if (!pareado[v] && !pareado[u])
pareado[u]=pareado[v]=1, ans++;
}
}
int main() {
int n; cin >> n;
for(int i=1; i<n; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b), adj[b].push_back(a);
}
dfs(1,1);
cout << ans << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment