Submission #986690

#TimeUsernameProblemLanguageResultExecution timeMemory
986690KasymKRace (IOI11_race)C++17
21 / 100
24 ms9300 KiB
#include "bits/stdc++.h" #define MAX_N 500000 #define ff first #define ss second using namespace std; const int Na = 1e3 + 5; vector<pair<int, int>> adj[Na]; int vis[Na], dis[Na], edge[Na]; int best_path(int n, int k, int H[][2], int L[]){ for(int i = 0; i < n - 1; ++i) adj[H[i][0]].push_back({H[i][1], L[i]}), adj[H[i][1]].push_back({H[i][0], L[i]}); queue<int> q; int answer = INT_MAX; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j) vis[j] = 0, dis[j] = 0, edge[j] = 0; while(!q.empty()) q.pop(); q.push(i); vis[i] = 1; while(!q.empty()){ int x = q.front(); q.pop(); for(auto &to : adj[x]) if(!vis[to.ff]){ dis[to.ff] = dis[x] + to.ss; edge[to.ff] = edge[x] + 1; vis[to.ff] = 1; q.push(to.ff); } } for(int j = 0; j < n; ++j) if(dis[j] == k) answer = min(answer, edge[j]); } return (answer == INT_MAX ? -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...