Submission #986690

# Submission time Handle Problem Language Result Execution time Memory
986690 2024-05-21T03:56:25 Z KasymK Race (IOI11_race) C++17
21 / 100
24 ms 9300 KB
#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 time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 13 ms 2396 KB Output is correct
22 Correct 11 ms 2396 KB Output is correct
23 Correct 14 ms 2396 KB Output is correct
24 Correct 10 ms 2396 KB Output is correct
25 Correct 10 ms 2392 KB Output is correct
26 Correct 10 ms 2396 KB Output is correct
27 Correct 10 ms 2396 KB Output is correct
28 Correct 11 ms 2396 KB Output is correct
29 Correct 11 ms 2396 KB Output is correct
30 Correct 10 ms 2516 KB Output is correct
31 Correct 10 ms 2572 KB Output is correct
32 Correct 10 ms 2396 KB Output is correct
33 Correct 11 ms 2572 KB Output is correct
34 Correct 8 ms 2396 KB Output is correct
35 Correct 6 ms 2528 KB Output is correct
36 Correct 6 ms 2396 KB Output is correct
37 Correct 5 ms 2396 KB Output is correct
38 Correct 7 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Runtime error 24 ms 9300 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 13 ms 2396 KB Output is correct
22 Correct 11 ms 2396 KB Output is correct
23 Correct 14 ms 2396 KB Output is correct
24 Correct 10 ms 2396 KB Output is correct
25 Correct 10 ms 2392 KB Output is correct
26 Correct 10 ms 2396 KB Output is correct
27 Correct 10 ms 2396 KB Output is correct
28 Correct 11 ms 2396 KB Output is correct
29 Correct 11 ms 2396 KB Output is correct
30 Correct 10 ms 2516 KB Output is correct
31 Correct 10 ms 2572 KB Output is correct
32 Correct 10 ms 2396 KB Output is correct
33 Correct 11 ms 2572 KB Output is correct
34 Correct 8 ms 2396 KB Output is correct
35 Correct 6 ms 2528 KB Output is correct
36 Correct 6 ms 2396 KB Output is correct
37 Correct 5 ms 2396 KB Output is correct
38 Correct 7 ms 2396 KB Output is correct
39 Runtime error 24 ms 9300 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -