이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define pii pair<int, ll>
#define ll long long
using namespace std;
ll TARGET;
const int INF = 1e9;
int BEST;
vector<vector<pii>> graph;
void DFS(int p, int node, ll w, int lenght){
if(w > TARGET) return;
if(w == TARGET) BEST = min(BEST,lenght);
for(auto &e: graph[node])
{
if(e.first == p) continue;
DFS(node, e.first, w + e.second, lenght + 1);
}
}
int best_path(int N, int K, int H[][2], int L[]){
graph.assign(N,vector<pii>{});
TARGET = K;
int a, b, l;
for(int i=0; i<N-1; i++)
{
a = H[i][0]; b = H[i][1]; l = L[i];
graph[a].push_back({b,l});
graph[b].push_back({a,l});
}
BEST = INF;
for(int i=0; i<N-1; i++) DFS(-1,i,0,0);
if(BEST == INF) 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... |