Submission #26579

# Submission time Handle Problem Language Result Execution time Memory
26579 2017-07-03T08:35:35 Z wwiiiii None (KOI16_gas) C++14
100 / 100
1008 ms 51900 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

class edge {
public:
	long long v, c;//vertex, cost
	bool operator<(const edge & next) const {
		if (c != next.c) return c > next.c;
		else return v > next.v;
	}
};

const long long vmax = 2520, emax = 4020, inf = vmax * emax * vmax;
long long n, m;
long long oil[vmax];
vector<edge> graph[vmax];
long long road[vmax][vmax];

void dijk(long long start)
{
	vector<long long> d(n + 1, inf);
	priority_queue<edge> pq;
	pq.push({ start, 0 });
	while (!pq.empty())
	{
		edge now = pq.top(); pq.pop();
		if (now.c > d[now.v]) continue;
		d[now.v] = now.c;
		for (auto next : graph[now.v])
		{
			if (d[next.v] > d[now.v] + next.c)
			{
				d[next.v] = d[now.v] + next.c;
				pq.push({ next.v, d[next.v] });
			}
		}
	}
	for (long long i = 1; i <= n; i++) {
		if (d[i] != inf) road[start][i] = d[i] * oil[start];
	}
}
long long ans()
{
	vector<long long> d(n + 1, inf);
	vector<bool> check(n + 1, false);
	d[1] = 0;
	while (true)
	{
		int mini = 0;
		for (int i = 1; i <= n; i++)
		{
			if (check[i]) continue;
			if (d[mini] > d[i]) mini = i;
		}
		if (mini == 0) break;
		for (int next = 1; next <= n; next++)
		{
			if (d[next] > d[mini] + road[mini][next])
			{
				d[next] = d[mini] + road[mini][next];
			}
		}
		check[mini] = true;
	}
	return d[n];
}

int main()
{
	scanf("%lld %lld", &n, &m);
	for (long long i = 1; i <= n; i++) scanf("%lld", &oil[i]);
	for (long long i = 0; i < m; i++)
	{
		long long s, e, c; scanf("%lld %lld %lld", &s, &e, &c);
		graph[s].push_back({ e, c });
		graph[e].push_back({ s, c });
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			road[i][j] = inf;
	for (long long i = 1; i <= n; i++) dijk(i);
	printf("%lld", ans());
}


Compilation message

gas.cpp: In function 'int main()':
gas.cpp:73:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &m);
                            ^
gas.cpp:74:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (long long i = 1; i <= n; i++) scanf("%lld", &oil[i]);
                                                           ^
gas.cpp:77:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   long long s, e, c; scanf("%lld %lld %lld", &s, &e, &c);
                                                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 51620 KB Output is correct
2 Correct 0 ms 51620 KB Output is correct
3 Correct 0 ms 51620 KB Output is correct
4 Correct 0 ms 51620 KB Output is correct
5 Correct 0 ms 51620 KB Output is correct
6 Correct 0 ms 51620 KB Output is correct
7 Correct 0 ms 51620 KB Output is correct
8 Correct 0 ms 51620 KB Output is correct
9 Correct 0 ms 51620 KB Output is correct
10 Correct 0 ms 51620 KB Output is correct
11 Correct 0 ms 51620 KB Output is correct
12 Correct 0 ms 51620 KB Output is correct
13 Correct 0 ms 51620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 51752 KB Output is correct
2 Correct 179 ms 51752 KB Output is correct
3 Correct 186 ms 51752 KB Output is correct
4 Correct 189 ms 51752 KB Output is correct
5 Correct 196 ms 51752 KB Output is correct
6 Correct 183 ms 51752 KB Output is correct
7 Correct 179 ms 51752 KB Output is correct
8 Correct 183 ms 51752 KB Output is correct
9 Correct 163 ms 51752 KB Output is correct
10 Correct 153 ms 51752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 51752 KB Output is correct
2 Correct 809 ms 51884 KB Output is correct
3 Correct 789 ms 51884 KB Output is correct
4 Correct 813 ms 51884 KB Output is correct
5 Correct 819 ms 51884 KB Output is correct
6 Correct 949 ms 51884 KB Output is correct
7 Correct 1008 ms 51884 KB Output is correct
8 Correct 1008 ms 51884 KB Output is correct
9 Correct 806 ms 51900 KB Output is correct
10 Correct 836 ms 51900 KB Output is correct
11 Correct 799 ms 51900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 51620 KB Output is correct
2 Correct 0 ms 51620 KB Output is correct
3 Correct 0 ms 51620 KB Output is correct
4 Correct 0 ms 51620 KB Output is correct
5 Correct 0 ms 51620 KB Output is correct
6 Correct 0 ms 51620 KB Output is correct
7 Correct 0 ms 51620 KB Output is correct
8 Correct 0 ms 51620 KB Output is correct
9 Correct 0 ms 51620 KB Output is correct
10 Correct 0 ms 51620 KB Output is correct
11 Correct 0 ms 51620 KB Output is correct
12 Correct 0 ms 51620 KB Output is correct
13 Correct 0 ms 51620 KB Output is correct
14 Correct 6 ms 51620 KB Output is correct
15 Correct 6 ms 51620 KB Output is correct
16 Correct 9 ms 51620 KB Output is correct
17 Correct 59 ms 51752 KB Output is correct
18 Correct 59 ms 51752 KB Output is correct
19 Correct 23 ms 51620 KB Output is correct
20 Correct 26 ms 51620 KB Output is correct
21 Correct 19 ms 51620 KB Output is correct
22 Correct 23 ms 51620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 51620 KB Output is correct
2 Correct 0 ms 51620 KB Output is correct
3 Correct 0 ms 51620 KB Output is correct
4 Correct 0 ms 51620 KB Output is correct
5 Correct 0 ms 51620 KB Output is correct
6 Correct 0 ms 51620 KB Output is correct
7 Correct 0 ms 51620 KB Output is correct
8 Correct 0 ms 51620 KB Output is correct
9 Correct 0 ms 51620 KB Output is correct
10 Correct 0 ms 51620 KB Output is correct
11 Correct 0 ms 51620 KB Output is correct
12 Correct 0 ms 51620 KB Output is correct
13 Correct 0 ms 51620 KB Output is correct
14 Correct 183 ms 51752 KB Output is correct
15 Correct 179 ms 51752 KB Output is correct
16 Correct 186 ms 51752 KB Output is correct
17 Correct 189 ms 51752 KB Output is correct
18 Correct 196 ms 51752 KB Output is correct
19 Correct 183 ms 51752 KB Output is correct
20 Correct 179 ms 51752 KB Output is correct
21 Correct 183 ms 51752 KB Output is correct
22 Correct 163 ms 51752 KB Output is correct
23 Correct 153 ms 51752 KB Output is correct
24 Correct 203 ms 51752 KB Output is correct
25 Correct 809 ms 51884 KB Output is correct
26 Correct 789 ms 51884 KB Output is correct
27 Correct 813 ms 51884 KB Output is correct
28 Correct 819 ms 51884 KB Output is correct
29 Correct 949 ms 51884 KB Output is correct
30 Correct 1008 ms 51884 KB Output is correct
31 Correct 1008 ms 51884 KB Output is correct
32 Correct 806 ms 51900 KB Output is correct
33 Correct 836 ms 51900 KB Output is correct
34 Correct 799 ms 51900 KB Output is correct
35 Correct 6 ms 51620 KB Output is correct
36 Correct 6 ms 51620 KB Output is correct
37 Correct 9 ms 51620 KB Output is correct
38 Correct 59 ms 51752 KB Output is correct
39 Correct 59 ms 51752 KB Output is correct
40 Correct 23 ms 51620 KB Output is correct
41 Correct 26 ms 51620 KB Output is correct
42 Correct 19 ms 51620 KB Output is correct
43 Correct 23 ms 51620 KB Output is correct
44 Correct 323 ms 51752 KB Output is correct
45 Correct 396 ms 51752 KB Output is correct
46 Correct 436 ms 51752 KB Output is correct
47 Correct 809 ms 51884 KB Output is correct
48 Correct 826 ms 51884 KB Output is correct
49 Correct 703 ms 51900 KB Output is correct
50 Correct 656 ms 51900 KB Output is correct
51 Correct 659 ms 51896 KB Output is correct
52 Correct 719 ms 51896 KB Output is correct