Codeforces Round 915 (Div. 2) 1905B - Begginer's Zelda Solution
Problem Link: https://codeforces.com/problemset/problem/1905/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ; cin >> n ;
- int u , v ;
- vector < int > cnt(n+2,0) ;
- for ( int i = 0 ; i < n - 1 ; i++){
- cin >> u >> v ;
- cnt[u]++ ;
- cnt[v]++ ;
- }
- int ans = 0 ;
- for (int i = 1 ; i <= n ; i++){
- if (cnt[i] == 1) ans++ ;
- }
- ans++ ;
- cout << ans / 2 <<'\n';
- }
- return 0 ;
- }
No comments