# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
691180 | boyliguanhan | Race (IOI11_race) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
#include <vector>
#include <pair>
vector<pair<int, int>> adj[200000];
int dis[2][1000][1000];
int best_path(int N, int K, int H[][2], int L[]) {
memset(dis, 1, sizeof dis);
for(int i = 0; i < N-1; i++)
dis[h[i][0]][h[i][1]][0] = 1, dis[h[i][1]][h[i][0]][0] = 1, dis[h[i][0]][h[i][1]][1] = L[i], dis[h[i][1]][h[i][0]][0] = L[i];
for(int x = 0; x < 2; x++)
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
for(int k = 0; k < N; k++)
dis[x][j][k] = min(dis[x][j][k], dis[x][j][i]+dis[x][i][k]);
int ans = 100000;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(dis[i][j][1]==K)
ans = min(ans, dis[i][j][0]);
return ans>N?-1:ans;
}