Submission #1000790

#TimeUsernameProblemLanguageResultExecution timeMemory
1000790NomioRace (IOI11_race)C++17
0 / 100
620 ms262144 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int best_path(int n, int k, int H[][2], int L[]) { vector<int> adj[n]; ll dis[n][n] {}; int cost[n][n], D[n][n] {}; for(int i = 0; i < n - 1; i++) { adj[H[i][0]].push_back(H[i][1]); adj[H[i][1]].push_back(H[i][0]); cost[H[i][0]][H[i][1]] = L[i]; cost[H[i][1]][H[i][0]] = L[i]; } for(int i = 0; i < n; i++) { queue<int> q; q.push(i); while(!q.empty()) { int x = q.front(); q.pop(); for(int X : adj[x]) { dis[i][X] = dis[i][x] + cost[x][X]; D[i][X] = D[i][x] + 1; q.push(X); } } } int mn = 1e9; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == j) continue; if(dis[i][j] == k) { mn = min(mn, D[i][j]); } } } if(mn == 1e9) mn = -1; return mn; } //int main() { // ios::sync_with_stdio(0); // cin.tie(0); // cout << best_path(3, 3, {{0, 1}, {1, 2}}, {1, 1}) << '\n'; // 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...