Submission #864512

# Submission time Handle Problem Language Result Execution time Memory
864512 2023-10-23T06:32:43 Z maks007 Toll (BOI17_toll) C++14
18 / 100
3000 ms 6940 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];
	vector <int> used(n);
	function <void(int)> dfs=[&](int v) {
		used[v] = 1;
		for(auto [u, w] : g[v]) {
			if(!used[u]) dfs(u);
			else if(used[u] == 1) {
				assert(false);
			}	
		}
		used[v] = 2;
	};
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		int w;
		cin >> w;
		g[u].push_back({v, w});
	}
	for(int i = 0; i < n; i ++) {
		if(used[i] == 0) dfs(i);
	}
	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 {
			vector <int> dist2(n, 1e9);
			dist2[a] = 0;
			q.push({0, a});
			while(!q.empty()) {
				int v = q.top().second, cur_d = q.top().first;
				q.pop();
				if(cur_d > dist2[v]) continue;
					for(auto [u, w] : g[v]) {
					if(dist2[u] > dist2[v] + w) {
						dist2[u] = dist2[v] + w;
						q.push({-dist2[u], u});
					}
				}
			}
			if(dist2[b] == 1e9) cout << -1;
			else cout << dist2[b];
			cout << "\n";
		}
	}
	return 0;
}

Compilation message

toll.cpp: In lambda function:
toll.cpp:13:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   13 |   for(auto [u, w] : g[v]) {
      |            ^
toll.cpp: In function 'int main()':
toll.cpp:39:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |   for(auto [u, w] : g[v]) {
      |            ^
toll.cpp:62:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |      for(auto [u, w] : g[v]) {
      |               ^
# Verdict Execution time Memory Grader output
1 Execution timed out 3056 ms 6940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4180 KB Output is correct
2 Correct 1 ms 344 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 524 KB Output is correct
8 Correct 16 ms 348 KB Output is correct
9 Correct 53 ms 3668 KB Output is correct
10 Correct 104 ms 5468 KB Output is correct
11 Correct 83 ms 5200 KB Output is correct
12 Correct 63 ms 3408 KB Output is correct
13 Correct 99 ms 4432 KB Output is correct
14 Correct 63 ms 3412 KB Output is correct
15 Correct 55 ms 2900 KB Output is correct
16 Correct 53 ms 2852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 11 ms 348 KB Output is correct
9 Correct 8 ms 344 KB Output is correct
10 Correct 38 ms 3980 KB Output is correct
11 Correct 229 ms 5208 KB Output is correct
12 Correct 347 ms 5676 KB Output is correct
13 Correct 383 ms 5776 KB Output is correct
14 Correct 309 ms 5512 KB Output is correct
15 Correct 213 ms 3140 KB Output is correct
16 Correct 203 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 11 ms 348 KB Output is correct
9 Correct 8 ms 344 KB Output is correct
10 Correct 38 ms 3980 KB Output is correct
11 Correct 229 ms 5208 KB Output is correct
12 Correct 347 ms 5676 KB Output is correct
13 Correct 383 ms 5776 KB Output is correct
14 Correct 309 ms 5512 KB Output is correct
15 Correct 213 ms 3140 KB Output is correct
16 Correct 203 ms 3152 KB Output is correct
17 Execution timed out 3049 ms 5404 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3056 ms 6940 KB Time limit exceeded
2 Halted 0 ms 0 KB -