이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ar=array<int,2>;
int n,k,res=1e6;
vector<ar>g[200000];
int sz[200000];
bool used[200000];
map<ll,int>mp;
void siz(int v, int e){
sz[v]=1;
for(const auto&[i,w]:g[v])
if(i!=e and !used[i]) siz(i,v),sz[v]+=sz[i];
}
int get(int v, int e, int des){
for(const auto&[i,w]:g[v])
if(i!=e and !used[i] and sz[i]>des) return get(i,v,des);
return v;
}
void help(int v, int e, ll km, int d, bool fill){
if(km>k) return;
if(fill){
if(mp[km]==0) mp[km]=d;
else mp[k-km]=min(mp[k-km],d);
}
else{
if(km==k) res=min(res,d);
else if(mp[k-km]!=0) res=min(res,d+mp[k-km]);
}
for(const auto&[i,w]:g[v])
if(!used[i]) help(i,v,km+w,d+1,fill);
}
void decomp(int v=0){
siz(v,-1);
int c=get(v,-1,sz[v]>>1);
used[c]=1;
mp[c]=0;
for(const auto&[i,w]:g[c])
if(!used[i]){
help(i,c,w,1,0);
help(i,c,w,1,1);
}
mp.clear();
for(const auto&[i,w]:g[c])
if(!used[i]) decomp(i);
}
int best_path(int N, int K, int H[][2],int L[]){
n=N;
k=K;
for(int i=0;i<n-1;++i){
g[H[i][0]].push_back({H[i][1],L[i]});
g[H[i][1]].push_back({H[i][0],L[i]});
}
decomp();
if(res==1e6) return -1;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void siz(int, int)':
race.cpp:12:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | for(const auto&[i,w]:g[v])
| ^
race.cpp: In function 'int get(int, int, int)':
race.cpp:16:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for(const auto&[i,w]:g[v])
| ^
race.cpp: In function 'void help(int, int, ll, int, bool)':
race.cpp:30:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for(const auto&[i,w]:g[v])
| ^
race.cpp: In function 'void decomp(int)':
race.cpp:38:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
38 | for(const auto&[i,w]:g[c])
| ^
race.cpp:44:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(const auto&[i,w]:g[c])
| ^
# | 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... |