이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
long long n,k,dp[200500],siz[200500],dis[200500],mn=1e9;
vector<pair<long long,long long> >gr[200500];
multiset<pair<long long,long long> >v[200500];
multiset<pair<long long,long long> >::iterator it;
void cal(int x,int p)
{
dp[x]=dp[p]+1;
siz[x]++;
for(int i=0; i<gr[x].size(); i++)
{
long long u=gr[x][i].first,w=gr[x][i].second;
if(u==p)continue;
dis[u]=dis[x]+w;
cal(u,x);
siz[x]+=siz[u];
}
}
void dfs(int x,int p)
{
long long big=0,mx=-1;
for(int i=0; i<gr[x].size(); i++)
{
long long u=gr[x][i].first;
if(u==p)continue;
if(mx<siz[u])
{
mx=siz[u];
big=u;
}
}
if(mx!=-1)dfs(big,x);
swap(v[big],v[x]);
v[x].insert({dis[x],dp[x]});
pair<long long,long long>zz=*v[x].lower_bound(make_pair(k+dis[x],0ll));
if(zz.first==k+dis[x]&&v[x].lower_bound(make_pair(k+dis[x],0ll))!=v[x].end())
{
long long add=zz.second-dp[x];
mn=min(mn,add);
}
for(int i=0; i<gr[x].size(); i++)
{
long long u=gr[x][i].first;
if(u==p||u==big)continue;
dfs(u,x);
}
for(int i=0; i<gr[x].size(); i++)
{
long long u=gr[x][i].first;
if(u==p||u==big)continue;
for(it=v[u].begin(); it!=v[u].end(); it++)
{
pair<long long,long long>z=*it;
long long dd=k-z.first+(2*dis[x]),add=z.second-dp[x];
pair<long long,long long>zz=*v[x].lower_bound(make_pair(dd,0ll));
if(zz.first+z.first==k+(2*dis[x])&&v[x].lower_bound(make_pair(dd,0ll))!=v[x].end())
{
long long add1=zz.second-dp[x];
mn=min(mn,add1+add);
}
v[x].insert(z);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n=N,k=K;
for(int i=0; i<n-1; i++)
{
int x=H[i][0]+1,y=H[i][1]+1;
gr[x].push_back({y,L[i]});
gr[y].push_back({x,L[i]});
}
cal(1,0);
dfs(1,0);
if(mn!=1e9)return mn;
else return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void cal(int, int)':
race.cpp:14:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gr[x].size(); i++)
~^~~~~~~~~~~~~
race.cpp: In function 'void dfs(int, int)':
race.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gr[x].size(); i++)
~^~~~~~~~~~~~~
race.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gr[x].size(); i++)
~^~~~~~~~~~~~~
race.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gr[x].size(); i++)
~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |