Submission #162990

# Submission time Handle Problem Language Result Execution time Memory
162990 2019-11-10T16:39:24 Z Minnakhmetov Toll (BOI17_toll) C++14
56 / 100
3000 ms 26892 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

struct E {
	int a, b, w;
};

const int N = 1e6 + 5, INF = 1e9;
E e[N];
int d[N], ans[N], used[N];
vector<pair<int, int>> v[N];
int fl = 0;
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, m, k, o;
    cin >> k >> n >> m >> o;

    for (int i = 0; i < m; i++) {
    	cin >> e[i].a >> e[i].b >> e[i].w;
    }

    sort(e, e + m, [](E x, E y) {
    	return x.a < y.a;
    });

    for (int i = 0; i < o; i++) {
    	int x, y;
    	cin >> x >> y;
    	v[x].push_back({y, i});
    }

    for (int i = 0, p = 0; i < n; i++) {
    	if (!v[i].empty()) {

    		while (p < m && e[p].a < i)
    			p++;
    		
    		fl++;

	    	d[i] = 0;
	    	used[i] = fl;

	    	for (int j = p; j < m; j++) {
	    		if (used[e[j].a] == fl) {
	    			if (used[e[j].b] != fl) {
	    				d[e[j].b] = INF;
	    				used[e[j].b] = fl;
	    			}
	    			d[e[j].b] = min(d[e[j].b], d[e[j].a] + e[j].w);
	    		}
	    	}

	    	for (auto p : v[i]) {
	    		if (used[p.first] == fl)
	    			ans[p.second] = d[p.first];
	    		else
	    			ans[p.second] = -1;
	    	}
    	}
    }

    for (int i = 0; i < o; i++) {
    	cout << ans[i] << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 25208 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 24 ms 23856 KB Output is correct
5 Correct 26 ms 24056 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 338 ms 25180 KB Output is correct
9 Correct 301 ms 25204 KB Output is correct
10 Correct 32 ms 24568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 25440 KB Output is correct
2 Correct 26 ms 23900 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 28 ms 24184 KB Output is correct
8 Correct 28 ms 24184 KB Output is correct
9 Correct 47 ms 24696 KB Output is correct
10 Correct 83 ms 26104 KB Output is correct
11 Correct 70 ms 25720 KB Output is correct
12 Correct 59 ms 25080 KB Output is correct
13 Correct 86 ms 25972 KB Output is correct
14 Correct 63 ms 25336 KB Output is correct
15 Correct 56 ms 25144 KB Output is correct
16 Correct 56 ms 25052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23852 KB Output is correct
2 Correct 24 ms 23804 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 24 ms 23928 KB Output is correct
5 Correct 26 ms 23928 KB Output is correct
6 Correct 27 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 27 ms 23928 KB Output is correct
10 Correct 48 ms 24824 KB Output is correct
11 Correct 93 ms 25336 KB Output is correct
12 Correct 122 ms 25880 KB Output is correct
13 Correct 125 ms 26104 KB Output is correct
14 Correct 119 ms 25592 KB Output is correct
15 Correct 91 ms 25052 KB Output is correct
16 Correct 90 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23852 KB Output is correct
2 Correct 24 ms 23804 KB Output is correct
3 Correct 24 ms 23928 KB Output is correct
4 Correct 24 ms 23928 KB Output is correct
5 Correct 26 ms 23928 KB Output is correct
6 Correct 27 ms 23800 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 27 ms 23928 KB Output is correct
9 Correct 27 ms 23928 KB Output is correct
10 Correct 48 ms 24824 KB Output is correct
11 Correct 93 ms 25336 KB Output is correct
12 Correct 122 ms 25880 KB Output is correct
13 Correct 125 ms 26104 KB Output is correct
14 Correct 119 ms 25592 KB Output is correct
15 Correct 91 ms 25052 KB Output is correct
16 Correct 90 ms 24952 KB Output is correct
17 Correct 898 ms 25520 KB Output is correct
18 Correct 26 ms 23800 KB Output is correct
19 Correct 25 ms 23800 KB Output is correct
20 Correct 25 ms 23892 KB Output is correct
21 Correct 26 ms 23928 KB Output is correct
22 Correct 26 ms 23928 KB Output is correct
23 Correct 26 ms 23900 KB Output is correct
24 Correct 31 ms 24056 KB Output is correct
25 Correct 37 ms 24056 KB Output is correct
26 Correct 34 ms 24056 KB Output is correct
27 Correct 142 ms 24956 KB Output is correct
28 Correct 1379 ms 26104 KB Output is correct
29 Correct 1218 ms 26204 KB Output is correct
30 Correct 817 ms 25848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 25208 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 24 ms 23856 KB Output is correct
5 Correct 26 ms 24056 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 338 ms 25180 KB Output is correct
9 Correct 301 ms 25204 KB Output is correct
10 Correct 32 ms 24568 KB Output is correct
11 Correct 67 ms 25440 KB Output is correct
12 Correct 26 ms 23900 KB Output is correct
13 Correct 24 ms 23928 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 25 ms 23800 KB Output is correct
16 Correct 24 ms 23928 KB Output is correct
17 Correct 28 ms 24184 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 47 ms 24696 KB Output is correct
20 Correct 83 ms 26104 KB Output is correct
21 Correct 70 ms 25720 KB Output is correct
22 Correct 59 ms 25080 KB Output is correct
23 Correct 86 ms 25972 KB Output is correct
24 Correct 63 ms 25336 KB Output is correct
25 Correct 56 ms 25144 KB Output is correct
26 Correct 56 ms 25052 KB Output is correct
27 Correct 25 ms 23852 KB Output is correct
28 Correct 24 ms 23804 KB Output is correct
29 Correct 24 ms 23928 KB Output is correct
30 Correct 24 ms 23928 KB Output is correct
31 Correct 26 ms 23928 KB Output is correct
32 Correct 27 ms 23800 KB Output is correct
33 Correct 25 ms 23928 KB Output is correct
34 Correct 27 ms 23928 KB Output is correct
35 Correct 27 ms 23928 KB Output is correct
36 Correct 48 ms 24824 KB Output is correct
37 Correct 93 ms 25336 KB Output is correct
38 Correct 122 ms 25880 KB Output is correct
39 Correct 125 ms 26104 KB Output is correct
40 Correct 119 ms 25592 KB Output is correct
41 Correct 91 ms 25052 KB Output is correct
42 Correct 90 ms 24952 KB Output is correct
43 Correct 898 ms 25520 KB Output is correct
44 Correct 26 ms 23800 KB Output is correct
45 Correct 25 ms 23800 KB Output is correct
46 Correct 25 ms 23892 KB Output is correct
47 Correct 26 ms 23928 KB Output is correct
48 Correct 26 ms 23928 KB Output is correct
49 Correct 26 ms 23900 KB Output is correct
50 Correct 31 ms 24056 KB Output is correct
51 Correct 37 ms 24056 KB Output is correct
52 Correct 34 ms 24056 KB Output is correct
53 Correct 142 ms 24956 KB Output is correct
54 Correct 1379 ms 26104 KB Output is correct
55 Correct 1218 ms 26204 KB Output is correct
56 Correct 817 ms 25848 KB Output is correct
57 Execution timed out 3042 ms 26892 KB Time limit exceeded
58 Halted 0 ms 0 KB -