이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;
const int maxn=2e5+10;
vector<pair<ll,int>> g[maxn];
pair<ll,int> dfs(int at, int p, int dst) {
if (at==dst) {
return {0,0};
}
for (auto ed: g[at]) {
int to = ed.second;
if (to==p) continue;
auto cur = dfs(to, at, dst);
if (cur.second != -1) {
cur.first += ed.first;
cur.second++;
return cur;
}
}
return {0,-1};
}
int best_path(int n, int k, int H[][2], int L[]) {
for (int i=0; i<n-1; i++) {
int u=H[i][0];
int v=H[i][1];
int w=L[i];
g[v].push_back({w,u});
g[u].push_back({w,v});
}
int best=n;
for (int i=0; i<n; i++) {
for (int j=i+1; j<n; j++) {
pair<ll,int> cur = dfs(i,i,j);
if (cur.first == k) {
best = min(best, cur.second);
}
}
}
return (best == n ? -1 : 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... |