Submission #987662

#TimeUsernameProblemLanguageResultExecution timeMemory
987662KasymKRace (IOI11_race)C++17
21 / 100
3065 ms16976 KiB
#include "bits/stdc++.h" #define MAX_N 500000 #define ff first #define ss second using namespace std; const int M = 2e5 + 5; vector<pair<int, int>> adj[M]; int vis[M], dis[M], edge[M]; 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]}); if(n <= 1e3 + 5){ queue<int> q; int answer = INT_MAX; for(int ad = 0; ad < n; ++ad){ for(int i = 0; i <= n; ++i) vis[i] = 0, dis[i] = 0, edge[i] = 0; while(!q.empty()) q.pop(); q.push(ad); vis[ad] = 1; while(!q.empty()){ int x = q.front(); q.pop(); for(auto &i : adj[x]) if(!vis[i.ff]){ vis[i.ff] = 1; q.push(i.ff); dis[i.ff] = dis[x] + i.ss; edge[i.ff] = edge[x] + 1; } } // dis[i] = ad-den i-e cenli uzaklyk // tree-da dine bir path bar for(int i = 0; i < n; ++i) if(dis[i] == k) answer = min(answer, edge[i]); } return (answer == INT_MAX ? -1 : answer); } else{ // n <= 200000 // k <= 100 } } //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; //}

Compilation message (stderr)

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
   52 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...