이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
#define MAX_N 500000
using namespace std;
vector<pii> G[200000];
int K;
bool vis[200000];
ll min(ll a, ll b){
if(a > b)
return b;
return a;
}
int best = 1e9;
void rec(int node, int cnt_nodes, int path, int parent){
if(path == K){
best = min(best, cnt_nodes);
return;
}
if(cnt_nodes >= best || path > K)
return;
if(!vis[node]){
vis[node] = true;
rec(node, 0, 0, -1);
}
for(auto next : G[node]){
if(next.first != parent){
rec(next.first, cnt_nodes + 1, path + next.second, node);
}
}
}
int best_path(int n, int k, int h[][2], int l[])
{
K = k;
for(int i = 0; i < n-1; i++){
G[h[i][0]].pb(mp(h[i][1], l[i]));
G[h[i][1]].pb(mp(h[i][0], l[i]));
}
memset(vis, false, sizeof(vis));
rec(0, 0, 0, -1);
if(best == 1e9)
return -1;
return best;
}
# | 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... |