Submission #864551

# Submission time Handle Problem Language Result Execution time Memory
864551 2023-10-23T07:49:33 Z iskhakkutbilim Toll (BOI17_toll) C++17
56 / 100
3000 ms 9096 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 5e4;
const int mod = 1e17;
vector< pair<int, int> > g[N];
int k, n, m, q;
main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
	cin >> k >> n >> m >> q;
	vector<int> dis(n, mod), parent(n, -1);
	for(int i = 0;i < m; i++){
		int a, b, w; cin >> a >> b >> w;
		
		g[a].push_back({b, w});
	}
	
	vector<pair<int, int> > Q;
	int z = 0;
	for(int i = 0;i < q; i++){
		int a, b; cin >> a >> b;
		z+= (a == 0);
		Q.push_back({a, b});
	}
	dis[0] = 0;
	for(int i = 0; i < n; i++){
		for(auto [to, w] : g[i]){
			if(dis[to] > dis[i] + w){
				dis[to] = dis[i] + w;
				parent[to] = i;
			}
		}
	}
	if(z == q){
		for(auto [a, b] : Q){
			if(a == b){
				cout << 0 << '\n';
				continue;
			}
			if(dis[b] >= mod) cout << "-1" << '\n';
			else cout << dis[b]<< '\n';
		}
		
		
		return 0;
	}
	
	for(auto [a, b] : Q){
		if(a == b){
			cout << 0 << '\n';
			continue;
		}
		for(int i = 0;i < n; i++) dis[i] = mod;
		dis[a] = 0;
		for(int i = a; i < n; i++){
			for(auto [to, w] : g[i]){
				if(dis[to] > dis[i] + w){
					dis[to] = dis[i] + w;
				}
			}
		}
		if(dis[b] >= mod) cout << "-1\n";
		else cout << dis[b] << '\n';
	}
	return 0;
}
 

Compilation message

toll.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1393 ms 4572 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 1143 ms 4292 KB Output is correct
9 Correct 1280 ms 4204 KB Output is correct
10 Correct 537 ms 2736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5248 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1416 KB Output is correct
5 Correct 1 ms 1624 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 2 ms 2032 KB Output is correct
8 Correct 3 ms 2140 KB Output is correct
9 Correct 14 ms 4956 KB Output is correct
10 Correct 37 ms 8196 KB Output is correct
11 Correct 27 ms 6608 KB Output is correct
12 Correct 20 ms 5720 KB Output is correct
13 Correct 37 ms 8528 KB Output is correct
14 Correct 26 ms 6000 KB Output is correct
15 Correct 24 ms 5112 KB Output is correct
16 Correct 19 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1628 KB Output is correct
10 Correct 24 ms 3928 KB Output is correct
11 Correct 60 ms 4932 KB Output is correct
12 Correct 92 ms 6584 KB Output is correct
13 Correct 91 ms 6748 KB Output is correct
14 Correct 83 ms 5580 KB Output is correct
15 Correct 59 ms 3932 KB Output is correct
16 Correct 59 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1628 KB Output is correct
10 Correct 24 ms 3928 KB Output is correct
11 Correct 60 ms 4932 KB Output is correct
12 Correct 92 ms 6584 KB Output is correct
13 Correct 91 ms 6748 KB Output is correct
14 Correct 83 ms 5580 KB Output is correct
15 Correct 59 ms 3932 KB Output is correct
16 Correct 59 ms 3932 KB Output is correct
17 Correct 1112 ms 5080 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1624 KB Output is correct
23 Correct 7 ms 1648 KB Output is correct
24 Correct 10 ms 1844 KB Output is correct
25 Correct 20 ms 1880 KB Output is correct
26 Correct 16 ms 1628 KB Output is correct
27 Correct 387 ms 4096 KB Output is correct
28 Correct 1732 ms 6492 KB Output is correct
29 Correct 1671 ms 6888 KB Output is correct
30 Correct 1230 ms 5684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1393 ms 4572 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 1143 ms 4292 KB Output is correct
9 Correct 1280 ms 4204 KB Output is correct
10 Correct 537 ms 2736 KB Output is correct
11 Correct 24 ms 5248 KB Output is correct
12 Correct 1 ms 1624 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1416 KB Output is correct
15 Correct 1 ms 1624 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 2 ms 2032 KB Output is correct
18 Correct 3 ms 2140 KB Output is correct
19 Correct 14 ms 4956 KB Output is correct
20 Correct 37 ms 8196 KB Output is correct
21 Correct 27 ms 6608 KB Output is correct
22 Correct 20 ms 5720 KB Output is correct
23 Correct 37 ms 8528 KB Output is correct
24 Correct 26 ms 6000 KB Output is correct
25 Correct 24 ms 5112 KB Output is correct
26 Correct 19 ms 5212 KB Output is correct
27 Correct 1 ms 1628 KB Output is correct
28 Correct 1 ms 1628 KB Output is correct
29 Correct 1 ms 1628 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 1 ms 1628 KB Output is correct
34 Correct 2 ms 1628 KB Output is correct
35 Correct 2 ms 1628 KB Output is correct
36 Correct 24 ms 3928 KB Output is correct
37 Correct 60 ms 4932 KB Output is correct
38 Correct 92 ms 6584 KB Output is correct
39 Correct 91 ms 6748 KB Output is correct
40 Correct 83 ms 5580 KB Output is correct
41 Correct 59 ms 3932 KB Output is correct
42 Correct 59 ms 3932 KB Output is correct
43 Correct 1112 ms 5080 KB Output is correct
44 Correct 1 ms 1628 KB Output is correct
45 Correct 1 ms 1372 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 1 ms 1628 KB Output is correct
48 Correct 1 ms 1624 KB Output is correct
49 Correct 7 ms 1648 KB Output is correct
50 Correct 10 ms 1844 KB Output is correct
51 Correct 20 ms 1880 KB Output is correct
52 Correct 16 ms 1628 KB Output is correct
53 Correct 387 ms 4096 KB Output is correct
54 Correct 1732 ms 6492 KB Output is correct
55 Correct 1671 ms 6888 KB Output is correct
56 Correct 1230 ms 5684 KB Output is correct
57 Execution timed out 3051 ms 9096 KB Time limit exceeded
58 Halted 0 ms 0 KB -