이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
int n,k,sz[100005],lv[100005],P[20][100005],vis[100005],ans=1e9,val[1000005];
vector<pair<int,int> > adj[100005];
int size(int u,int p){
sz[u] = 1;
for(auto [v,x] : adj[u]) if(!vis[v] && v != p) sz[u] += size(v,u);
return sz[u];
}
int find_cen(int u,int p,int s){
for(auto [v,x] : adj[u]) if(!vis[v] && v != p && sz[v] > s/2) return find_cen(v,u,s);
return u;
}
void dfs(int u,int p,int len,int lv,int mode){
if(mode == 0){
ans = min(ans, lv + val[k - len]);
//printf("!! %d %d : %d %d\n",u,len,lv,val[k-len]);
for(auto [v,w] : adj[u]){
if(!vis[v] && v != p && len+w <= k){
dfs(v,u,len+w,lv+1,mode);
}
}
}
else if(mode == 1){
val[len] = min(val[len],lv);
//printf("!! %d %d\n",len,lv);
for(auto [v,w] : adj[u]){
if(!vis[v] && v != p && len+w <= k){
dfs(v,u,len+w,lv+1,mode);
}
}
}
else if(mode == 2){
val[len] = 1e9;
for(auto [v,w] : adj[u]){
if(!vis[v] && v != p && len+w <= k){
dfs(v,u,len+w,lv+1,mode);
}
}
}
}
void process(int u){
size(u,u);
int c = find_cen(u,u,n);
//printf("cen : %d\n",c);
vis[c] = 1;
for(auto [v,w] : adj[c]){
if(!vis[v] && w <= k){
dfs(v,u,w,1,0);
dfs(v,u,w,1,1);
}
}
for(auto [v,w] : adj[c]){
if(!vis[v] && w <= k){
dfs(v,u,w,1,2);
process(v);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N, k = K;
for(int i=0;i<n-1;i++){
adj[H[i][0]].push_back({H[i][1],L[i]});
adj[H[i][1]].push_back({H[i][0],L[i]});
}
for(int i=1;i<=1000000;i++) val[i] = 1e9;
process(1);
return (ans == 1e9) ? -1 : ans;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'int size(int, int)':
race.cpp:12:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | for(auto [v,x] : adj[u]) if(!vis[v] && v != p) sz[u] += size(v,u);
| ^
race.cpp: In function 'int find_cen(int, int, int)':
race.cpp:17:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | for(auto [v,x] : adj[u]) if(!vis[v] && v != p && sz[v] > s/2) return find_cen(v,u,s);
| ^
race.cpp: In function 'void dfs(int, int, int, int, int)':
race.cpp:25:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | for(auto [v,w] : adj[u]){
| ^
race.cpp:34:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for(auto [v,w] : adj[u]){
| ^
race.cpp:42:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto [v,w] : adj[u]){
| ^
race.cpp: In function 'void process(int)':
race.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [v,w] : adj[c]){
| ^
race.cpp:63:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
63 | for(auto [v,w] : adj[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... |