96692024-02-23 21:44:30999Átvágás (75 pont)cpp17Wrong answer 0/75212ms30652 KiB
#include <bits/stdc++.h>
using namespace std;

int main() 
{
  int n;cin>>n;
  vector<vector<int>> v(n+1);
  for(int i = 0;i<n-1;i++){
    int a,b;cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<int> dis(n+1,-1);
  int ans1=0;
  queue<int> q;
  int k=1;
  while(v[k].size()!=1)k++;
  q.push(k);
  dis[k]=0;
  while(!q.empty()){
    int node=q.front();
    q.pop();
    if(node!=k&&v[node].size()>2)ans1+=(int)v[node].size()-2;
    for(int i : v[node]){
      if(dis[i]==-1){
        q.push(i);
        dis[i]=dis[node]+1;
      }
    }
  }cout<<ans1<<' ';
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Wrong answer0/03ms1812 KiB
2Wrong answer0/03ms2052 KiB
3Wrong answer0/09ms3260 KiB
4Wrong answer0/42ms2348 KiB
5Wrong answer0/43ms2440 KiB
6Wrong answer0/43ms2652 KiB
7Wrong answer0/43ms2912 KiB
8Wrong answer0/43ms3104 KiB
9Wrong answer0/43ms3192 KiB
10Wrong answer0/4142ms30048 KiB
11Wrong answer0/4160ms29852 KiB
12Wrong answer0/4175ms30420 KiB
13Wrong answer0/4181ms30652 KiB
14Wrong answer0/4202ms29588 KiB
15Wrong answer0/4194ms28008 KiB
16Wrong answer0/4212ms27744 KiB
17Wrong answer0/4196ms27960 KiB
18Wrong answer0/5210ms28000 KiB
19Wrong answer0/6199ms27912 KiB
20Wrong answer0/6202ms27916 KiB
21Wrong answer0/23ms4536 KiB