Submission #41116

# Submission time Handle Problem Language Result Execution time Memory
41116 2018-02-13T01:00:04 Z 14kg None (KOI16_gas) C++11
100 / 100
51 ms 51904 KB
#include <stdio.h>
#include <queue>
#include <vector>
#include <functional>
#define INF 999999999999999999
#define min2(x,y) (x<y?x:y)

using namespace std;
typedef pair<long long, pair<int, int> > pip;
int n, in[2501];
long long d[2501][2501];
vector<pair<int, int> > r[2501];
priority_queue<pip, vector<pip>, greater<pip> > Q;

int main() {
	int m, x, y, z;
	pip t;

	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &in[i]);
	while (m--) {
		scanf("%d %d %d", &x, &y, &z);
		r[x].push_back({ y,z }), r[y].push_back({ x,z });
	}

	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= 2500; j++) d[i][j] = INF;
	
	Q.push({ 0,{1,2500} });
	while (!Q.empty()) {
		t = Q.top(), Q.pop();

		if (t.second.first == n) {
			printf("%lld", t.first);
			return 0;
		}

		t.second.second = min2(t.second.second, in[t.second.first]);
		for(auto i:r[t.second.first])
			if (d[i.first][t.second.second] > t.first + t.second.second*i.second) {
				d[i.first][t.second.second] = t.first + t.second.second*i.second;
				Q.push({ d[i.first][t.second.second],{i.first,t.second.second} });
			}
	}
}

Compilation message

gas.cpp: In function 'int main()':
gas.cpp:19:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
gas.cpp:20:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &in[i]);
                                                  ^
gas.cpp:22:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &x, &y, &z);
                                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
4 Correct 2 ms 848 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 864 KB Output is correct
11 Correct 2 ms 868 KB Output is correct
12 Correct 2 ms 872 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 49776 KB Output is correct
2 Correct 37 ms 49824 KB Output is correct
3 Correct 42 ms 50016 KB Output is correct
4 Correct 37 ms 50016 KB Output is correct
5 Correct 37 ms 50112 KB Output is correct
6 Correct 36 ms 50112 KB Output is correct
7 Correct 37 ms 50112 KB Output is correct
8 Correct 48 ms 50192 KB Output is correct
9 Correct 36 ms 50232 KB Output is correct
10 Correct 38 ms 50356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 50388 KB Output is correct
2 Correct 41 ms 50508 KB Output is correct
3 Correct 41 ms 50668 KB Output is correct
4 Correct 37 ms 50668 KB Output is correct
5 Correct 38 ms 50784 KB Output is correct
6 Correct 38 ms 50784 KB Output is correct
7 Correct 38 ms 50896 KB Output is correct
8 Correct 37 ms 50936 KB Output is correct
9 Correct 38 ms 50964 KB Output is correct
10 Correct 38 ms 51012 KB Output is correct
11 Correct 37 ms 51064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
4 Correct 2 ms 848 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 864 KB Output is correct
11 Correct 2 ms 868 KB Output is correct
12 Correct 2 ms 872 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 9 ms 51064 KB Output is correct
15 Correct 9 ms 51064 KB Output is correct
16 Correct 9 ms 51064 KB Output is correct
17 Correct 10 ms 51064 KB Output is correct
18 Correct 10 ms 51064 KB Output is correct
19 Correct 8 ms 51064 KB Output is correct
20 Correct 9 ms 51064 KB Output is correct
21 Correct 9 ms 51064 KB Output is correct
22 Correct 8 ms 51064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
4 Correct 2 ms 848 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 864 KB Output is correct
11 Correct 2 ms 868 KB Output is correct
12 Correct 2 ms 872 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 36 ms 49776 KB Output is correct
15 Correct 37 ms 49824 KB Output is correct
16 Correct 42 ms 50016 KB Output is correct
17 Correct 37 ms 50016 KB Output is correct
18 Correct 37 ms 50112 KB Output is correct
19 Correct 36 ms 50112 KB Output is correct
20 Correct 37 ms 50112 KB Output is correct
21 Correct 48 ms 50192 KB Output is correct
22 Correct 36 ms 50232 KB Output is correct
23 Correct 38 ms 50356 KB Output is correct
24 Correct 38 ms 50388 KB Output is correct
25 Correct 41 ms 50508 KB Output is correct
26 Correct 41 ms 50668 KB Output is correct
27 Correct 37 ms 50668 KB Output is correct
28 Correct 38 ms 50784 KB Output is correct
29 Correct 38 ms 50784 KB Output is correct
30 Correct 38 ms 50896 KB Output is correct
31 Correct 37 ms 50936 KB Output is correct
32 Correct 38 ms 50964 KB Output is correct
33 Correct 38 ms 51012 KB Output is correct
34 Correct 37 ms 51064 KB Output is correct
35 Correct 9 ms 51064 KB Output is correct
36 Correct 9 ms 51064 KB Output is correct
37 Correct 9 ms 51064 KB Output is correct
38 Correct 10 ms 51064 KB Output is correct
39 Correct 10 ms 51064 KB Output is correct
40 Correct 8 ms 51064 KB Output is correct
41 Correct 9 ms 51064 KB Output is correct
42 Correct 9 ms 51064 KB Output is correct
43 Correct 8 ms 51064 KB Output is correct
44 Correct 37 ms 51120 KB Output is correct
45 Correct 37 ms 51168 KB Output is correct
46 Correct 37 ms 51252 KB Output is correct
47 Correct 39 ms 51616 KB Output is correct
48 Correct 39 ms 51616 KB Output is correct
49 Correct 41 ms 51656 KB Output is correct
50 Correct 38 ms 51656 KB Output is correct
51 Correct 51 ms 51904 KB Output is correct
52 Correct 39 ms 51904 KB Output is correct