이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Coded by Chirath Nirodha
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define P push
typedef long long ll;
map<int,int> mp[1000000];
vector<pair<int,int> > adj[1000000];
int ans=10000010;
int kk;
void dfs(int x,int y){
for(int i=0;i<adj[y].size();i++){
int to=adj[y][i].F;
int len=adj[y][i].S;
if(to==x)continue;
dfs(y,to);
for(auto itr=mp[to].begin();itr!=mp[to].end();itr++){
pair<int,int> p=*itr;
if(p.F+len>kk)break;
if(p.F+len==kk)ans=min(ans,p.S+1);
else if(mp[y].count(kk-(p.F+len))!=0)ans=min(ans,p.S+1+mp[y][kk-(p.F+len)]);
}
if(len==kk)ans=1;
else if(mp[y].count(kk-len)!=0 && len<=kk)ans=min(ans,1+mp[y][kk-len]);
if(len<=kk)mp[y][len]=1;
for(auto itr=mp[to].begin();itr!=mp[to].end();itr++){
pair<int,int> p=*itr;
if(p.F+len>kk)break;
if(mp[y].count(p.F+len)==0)mp[y][p.F+len]=p.S+1;
else mp[y][p.F+len]=min(mp[y][p.F+len],p.S+1);
}
}
}
int best_path(int n, int K, int h[][2], int l[]){
kk=K;
for(int i=0;i<n-1;i++){
adj[h[i][0]].PB(MP(h[i][1],l[i]));
adj[h[i][1]].PB(MP(h[i][0],l[i]));
}
dfs(0,0);
if(ans>=n)return -1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void dfs(int, int)':
race.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<adj[y].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... |