제출 #1315454

#제출 시각아이디문제언어결과실행 시간메모리
1315454vlomaczk경주 (Race) (IOI11_race)C++20
21 / 100
3093 ms9872 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n,kk,inf=1e7;
int ans = inf;
int M = 200'010;
vector<vector<pair<int, int>>> g(M);

void dfs(int v, int p, int d, int c) {
	if(c==kk) ans = min(ans,d);
	for(auto[u,k] : g[v]) {
		if(u==p) continue;
		dfs(u,v,d+1,c+k);
	}
}

int best_path(int N, int K, int H[][2], int L[]) {
	n=N; kk=K;
	for(ll i=0; i<n-1; ++i) {
		ll a = H[i][0];
		ll b = H[i][1];
		ll c = L[i];
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	for(int i=0; i<n; ++i) {
		dfs(i,-1, 0,0);
	}
	if(ans==inf) return -1;
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...