Submission #1000790

# Submission time Handle Problem Language Result Execution time Memory
1000790 2024-06-18T08:50:46 Z Nomio Race (IOI11_race) C++17
0 / 100
620 ms 262144 KB
#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 time Memory Grader output
1 Runtime error 620 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -