이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
vector<long long>vs;
vector<long long>vs1;
vector<vector<pair<long long,long long>>>adj;
long long ans=1e6;
long long pog=0;
long long dp[200002][102];
void dfs(long long node,long long lol,long long sum)
{
vs[node]=true;
if(sum>pog)
return;
if(sum==pog)
{
ans=min(ans,lol);
return;
}
for(auto i:adj[node])
{
if(!vs[i.first])
{
// cout<<node<<" "<<i.first<<" "<<i.second<<endl;
dfs(i.first,lol+1,sum+i.second);
}
}
}
long long dfs1(long long node,long long sum,long long p)
{
if(sum>pog)
return 1e6;
if(sum==pog)
return 0;
if(dp[node][sum]!=-1)
return dp[node][sum];
long long e=1e6;
for(auto i:adj[node])
{
if(i.first==p)
continue;
e=min(e,dfs1(i.first,sum+i.second,node)+1);
}
return dp[node][sum]=e;
}
int best_path(int n, int k, int h[][2], int l[])
{
memset(dp,-1,sizeof dp);
pog=k;
adj.resize(n+1);
vs.resize(n+1);
vs1=vs;
for(int i=0; i<n-1; i++)
{
// cout<<h[i][0]<<" "<<h[i][1]<<" "<<l[i]<<endl;
adj[h[i][0]].push_back({h[i][1],l[i]});
adj[h[i][1]].push_back({h[i][0],l[i]});
}
if(n<=200000&&k<=100)
for(int i=0;i<n;i++)
ans=min(ans,dfs1(i,0,-1));
for(int i=0;i<n;i++)
dfs(i,0,0);
if(ans>=1e6)
ans=-1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:59:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
59 | if(n<=200000&&k<=100)
| ^~
race.cpp:62:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
62 | for(int i=0;i<n;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... |