답안 #1028573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028573 2024-07-20T05:12:57 Z MMihalev Torrent (COI16_torrent) C++14
0 / 100
74 ms 24460 KB
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<map>
#include<random>
#include<chrono>
#include<array>
using namespace std;
const int MAX_N=3e5+5;
vector<int>g[MAX_N];
int a,b;
int n;
int dfs(int u,int par)
{
    vector<int>mins;
    for(int v:g[u])
    {
        if(v==par or v==a or v==b)continue;
        mins.push_back(dfs(v,u));
    }
    int ans=0;
    for(int i=0;i<mins.size();i++)
    {
        ans=max(ans,mins[i]+i+1);
    }
    return ans;
}
signed main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>a>>b;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans=max(dfs(a,0),dfs(b,0));
    cout<<ans<<"\n";

    return 0;
}

Compilation message

torrent.cpp: In function 'int dfs(int, int)':
torrent.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0;i<mins.size();i++)
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 24460 KB Output isn't correct
2 Halted 0 ms 0 KB -