이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const ll mxn = 2e5L + 1;
vpl adj[mxn];
int dfs(ll cur, ll src, ll len, ll num, ll need) {
if(len == need)
return num;
else if(len > need)
return mxn;
for(auto [ch, wt] : adj[cur]) {
if(ch != src) {
return dfs(ch, cur, len + wt, num + 1, need);
}
}
return mxn;
}
int best_path(int N, int K, int H[][2], int L[])
{
fur(i, 0, N - 2) {
++H[i][0]; ++H[i][1];
adj[H[i][0]].pb(H[i][1], L[i]);
adj[H[i][1]].pb(H[i][0], L[i]);
}
int ans = N;
fur(i, 1, N) {
ans = min(ans, dfs(i, i - 1, 0, 0, K));
}
if(ans == N)
ans = -1;
return ans;
}
# | 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... |