이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fst first
#define nl endl
#define sec second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
#include "race.h"
vvpi paths(2e5+5);
int ans = 1e8;
bool solved = false;
void dfs(int pos,int prev,int cost,int K,int path){
if(path > ans)return;
if(cost > K)return;
if(cost == K){
ans = min(ans,path);
solved = true;
return;
}
for(auto a:paths[pos]){
if(a.fst == prev)continue;
dfs(a.fst,pos,cost+a.sec,K,path+1);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
ans = 1e8;
paths = vvpi(2e5+5);
solved = false;
FOR(i,0,N-1){
paths[H[i][0]].pb({H[i][1],L[i]});
paths[H[i][1]].pb({H[i][0],L[i]});
}
FOR(i,0,N){
dfs(i,-1,0,K,0);
}
if(solved){
return ans;
}
return -1;
}
# | 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... |