This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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,vi visited,int cost,int K,int path){
if(visited[pos])return;
visited[pos] = 1;
if(cost > K)return;
if(cost == K){
ans = min(ans,path);
solved = true;
return;
}
for(auto a:paths[pos]){
dfs(a.fst,visited,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){
vi visited(N,0);
dfs(i,visited,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... |