96682024-02-23 21:21:42999Átvágás (75 pont)cpp17Wrong answer 8/75236ms29864 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);
  dis[1]=0;
  queue<int> q;
  q.push(1);
  while(!q.empty()){
    int node=q.front();
    q.pop();
    for(int i : v[node]){
      if(dis[i]==-1){
        q.push(i);
        dis[i]=dis[node]+1;
      }
    }
  }
  int maxdis=1;
  for(int i = 1;i<=n;i++){
    if(dis[maxdis]<dis[i])maxdis=i;
  }
  fill(dis.begin(),dis.end(),-1);
  dis[maxdis]=1;
  q.push(maxdis);
  while(!q.empty()){
    int node=q.front();
    q.pop();
    for(int i : v[node]){
      if(dis[i]!=-1)continue;
      q.push(i);
      dis[i]=dis[node]+1;
    }
  }
  for(int i = 1;i<=n;i++){
    if(dis[maxdis]<dis[i])maxdis=i;
  }
  cout<<n-dis[maxdis]<<' ';
  //task 2:
  int cnt=0;
  int db=0;
  int sum=0;
  for(int i = 1;i<=n;i++){
    if(cnt==v[i].size())db++;
    else if(cnt<v[i].size()){
      sum+=v[cnt].size()-1;
      db=1;
      cnt=v[i].size();
    }
    else if(v[i].size()!=1){
      sum+=v[i].size()-1;
    }
  }
  int ans2=(db-1)*cnt+sum;
  cout<<ans2<<endl;
}
SubtaskSumTestVerdictTimeMemory
base8/75
1Accepted0/03ms1812 KiB
2Accepted0/03ms2000 KiB
3Wrong answer0/010ms3212 KiB
4Partially correct2/43ms2296 KiB
5Wrong answer0/43ms2428 KiB
6Partially correct2/43ms2544 KiB
7Wrong answer0/43ms2680 KiB
8Wrong answer0/43ms2760 KiB
9Wrong answer0/43ms2896 KiB
10Partially correct2/4148ms29484 KiB
11Wrong answer0/4163ms29188 KiB
12Wrong answer0/4181ms29860 KiB
13Wrong answer0/4185ms29864 KiB
14Wrong answer0/4199ms28952 KiB
15Wrong answer0/4209ms27552 KiB
16Wrong answer0/4212ms27028 KiB
17Wrong answer0/4217ms27308 KiB
18Wrong answer0/5212ms27076 KiB
19Wrong answer0/6216ms27120 KiB
20Wrong answer0/6236ms26992 KiB
21Accepted2/23ms3808 KiB