Submission #864516

# Submission time Handle Problem Language Result Execution time Memory
864516 2023-10-23T06:58:25 Z maks007 Toll (BOI17_toll) C++14
10 / 100
3000 ms 4312 KB
// Bismi ALlah
#include "bits/stdc++.h"

using namespace std;

signed main () {
	int n, m, k, query;
	cin >> k >> n >> m >> query;
	vector<pair <int,int>> g[n];
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		int w;
		cin >> w;
		g[u].push_back({v, w});
	}
	for(auto i : g) {
		sort(i.begin(), i.end(), [](pair <int,int> a, pair <int,int> b) {
			return a.second < b.second;
		});
	}
	priority_queue <pair <int,int>> q;
	vector <int> dist(n, 1e9);
	dist[0] = 0;
	q.push({0, 0});
	while(!q.empty()) {
		int v = q.top().second, cur_d = q.top().first;
		q.pop();
		if(cur_d > dist[v]) continue;
		for(auto [u, w] : g[v]) {
			if(dist[u] > dist[v] + w) {
				dist[u] = dist[v] + w;
				q.push({-dist[u], u});
			}
		}
	}
	while(query --) {
		int a, b;
		cin >> a >> b;
		
		if(a == 0) {
			if(dist[b] == 1e9) cout << -1 << "\n";
			else
			cout << dist[b] << "\n"; 
		}else {
			queue <int> q;
			vector <int> dist2(n, -1);
			dist2[a] = 0;
			q.push(a);
			while(!q.empty()) {
				int v = q.front();
				q.pop();
				for(auto [u, w] : g[v]) {
					if(dist2[u] == -1) {
						dist2[u] = dist2[v] + w;
						q.push(u);
					}
				}
			}
			if(dist2[b] == 1e9) cout << -1 << "\n";
			else cout << dist2[b] << "\n";
		}
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:30:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |   for(auto [u, w] : g[v]) {
      |            ^
toll.cpp:53:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |     for(auto [u, w] : g[v]) {
      |              ^
# Verdict Execution time Memory Grader output
1 Execution timed out 3046 ms 4060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 3408 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 15 ms 344 KB Output is correct
8 Correct 16 ms 348 KB Output is correct
9 Correct 48 ms 3564 KB Output is correct
10 Correct 108 ms 4312 KB Output is correct
11 Correct 84 ms 3288 KB Output is correct
12 Correct 64 ms 3148 KB Output is correct
13 Correct 105 ms 3820 KB Output is correct
14 Correct 66 ms 2896 KB Output is correct
15 Correct 56 ms 2336 KB Output is correct
16 Correct 56 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3046 ms 4060 KB Time limit exceeded
2 Halted 0 ms 0 KB -