Submission #1018642

# Submission time Handle Problem Language Result Execution time Memory
1018642 2024-07-10T07:46:49 Z vjudge1 Autobus (COCI22_autobus) C++17
30 / 70
1000 ms 2220 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define inf ((int)1e9)
using namespace std;
const int N = 71;
vector <pair<int, int> > adj[N];
vector <vector<vector<int> > > ans(N);

void dijkstra(int st, int K) { // 70 * 70 * 7
	// cout << st << ":\n";
	vector <vector<int> > dist(N, vector<int>(N, inf));
	priority_queue <array<int, 3>, vector<array<int,3> >, greater<array<int, 3>> > pq; // {k, -v, node}
	pq.push({0, 0, st});
	while(!pq.empty()) {
		auto [k, v, node] = pq.top();
		pq.pop();
		if(k > K or dist[node][k] < inf) continue;
		// cout << node << " " << k << " " << v << "\n";
		dist[node][k] = v;
		for(auto [to, w]:adj[node]) {
			if(dist[to][k + 1] == inf) {
				pq.push({k + 1, v + w, to});
			}
		}
	}
	ans[st] = dist;
};

int32_t main(){
	fast
	int n, m;
	cin >> n >> m;
	vector <vector<int> > temp(n+1, vector<int>(n + 1, inf));
	for(int i = 0; i < m; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		temp[a][b] = min(temp[a][b], w);
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if(i == j) temp[i][j] = 0;
			if(temp[i][j] == inf) continue;
			adj[i].push_back({j, temp[i][j]});
		}
	}
	int K, Q;
	cin >> K >> Q;
	K = min(K, n - 1);
	for(int i = 1; i <= n; i++) {
		dijkstra(i, K);
	}
	while(Q--) {
		int a, b;
		cin >> a >> b;
		cout << (ans[a][b][K] == inf ? -1 : ans[a][b][K]) << "\n";
	} 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 4 ms 2140 KB Output is correct
3 Correct 8 ms 2068 KB Output is correct
4 Correct 13 ms 2036 KB Output is correct
5 Correct 23 ms 2140 KB Output is correct
6 Correct 50 ms 2220 KB Output is correct
7 Correct 78 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 79 ms 2148 KB Output is correct
8 Correct 235 ms 2132 KB Output is correct
9 Correct 30 ms 2060 KB Output is correct
10 Correct 339 ms 2132 KB Output is correct
11 Correct 268 ms 2220 KB Output is correct
12 Execution timed out 1040 ms 1924 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 8 ms 2068 KB Output is correct
10 Correct 13 ms 2036 KB Output is correct
11 Correct 23 ms 2140 KB Output is correct
12 Correct 50 ms 2220 KB Output is correct
13 Correct 78 ms 2168 KB Output is correct
14 Correct 79 ms 2148 KB Output is correct
15 Correct 235 ms 2132 KB Output is correct
16 Correct 30 ms 2060 KB Output is correct
17 Correct 339 ms 2132 KB Output is correct
18 Correct 268 ms 2220 KB Output is correct
19 Execution timed out 1040 ms 1924 KB Time limit exceeded
20 Halted 0 ms 0 KB -