Submission #986438

#TimeUsernameProblemLanguageResultExecution timeMemory
986438KasymKRace (IOI11_race)C++17
0 / 100
1 ms2396 KiB
#include "bits/stdc++.h" //#include "race.h" #define MAX_N 500000 using namespace std; const int Na = 1e3 + 5; vector<pair<int, int>> adj[Na]; int mn = INT_MAX; int Ka; int dfs(int x, int pr, int gal, int edge){ if(!(gal^Ka)) return edge; if(gal > Ka) return Na; for(auto &i : adj[x]) if(i.first != pr) mn = min(mn, dfs(i.first, x, gal + i.second, edge + 1)); return mn; } int best_path(int n, int k, int H[][2], int L[]){ Ka = k; for(int i = 0; i < n; ++i){ int a = H[i][0], b = H[i][1]; adj[a].push_back({b, L[i]}); adj[b].push_back({a, L[i]}); } int answer = INT_MAX; for(int i = 0; i < n; ++i) answer = min(answer, dfs(i, -1, 0, 0)); return (answer >= Na ? -1 : answer); } //static int N, K; //static int H[MAX_N][2]; //static int L[MAX_N]; //static int solution; // //inline //void my_assert(int e) {if (!e) abort();} // //void read_input() //{ // int i; // my_assert(2==scanf("%d %d",&N,&K)); // for(i=0; i<N-1; i++) // my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i])); // my_assert(1==scanf("%d",&solution)); //} // //int main() { // int ans; // read_input(); // ans = best_path(N,K,H,L); // if(ans==solution) // printf("Correct.\n"); // else // printf("Incorrect. Returned %d, Expected %d.\n",ans,solution); // // return 0; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...