Submission #20639

# Submission time Handle Problem Language Result Execution time Memory
20639 2017-02-13T06:18:16 Z model_code None (KOI16_gas) C++11
100 / 100
1366 ms 50436 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

FILE *fp1 = stdin;
FILE *fp2 = stdout;

#define V 2500
#define INF 0x7fffffffffffffff
#define min2(x,y) ((x)<(y)?(x):(y))

int n, m;
int oil_v[V + 1];
vector<int> go[V + 1], d[V + 1];
long long shortest_d[V + 1][V + 1];
priority_queue< pair<int, long long>, vector<pair<int, long long> >, greater<pair<int, long long> > > q;

void input(void) {
int i;
int v1, v2, weight;
fscanf(fp1, "%d %d", &n, &m);
for (i = 1; i <= n; i++)
fscanf(fp1, "%d", &oil_v[i]);
for (i = 1; i <= m; i++) {
fscanf(fp1, "%d %d %d", &v1, &v2, &weight);
go[v1].push_back(v2);
d[v1].push_back(weight);
  go[v2].push_back(v1);
d[v2].push_back(weight);
}
}
void dijkstra(int start) {
int i, j, size_p;
bool check[V + 1];
pair<int, long long> t, tt;

for (i = 1; i <= n; i++)check[i] = false;

tt.first = 0; tt.second = start;
q.push(tt);
  for (i = 1; i <= n; i++) {
while (!q.empty()) {
t = q.top(); q.pop();
if (!check[t.second]) break;
}
check[t.second] = true;
size_p = go[t.second].size();
for (j = 0; j<size_p; j++) {
if (shortest_d[start][go[t.second][j]] > shortest_d[start][t.second] + oil_v[start] * d[t.second][j]) {
shortest_d[start][go[t.second][j]] = shortest_d[start][t.second] + oil_v[start] * d[t.second][j];
tt.first = shortest_d[start][go[t.second][j]];
tt.second = go[t.second][j];
q.push(tt);
}
}
}
while (!q.empty()) q.pop();
}
long long get_answer(void) {
int i, j, ii, jj;
pair<int, int> sorted_oil_v[V + 1];
long long min_cost[V + 1];

for (i = 1; i <= n; i++) {
sorted_oil_v[i].first = -oil_v[i];
sorted_oil_v[i].second = i;
}
sort(sorted_oil_v + 2, sorted_oil_v + n);

min_cost[1] = 0;
for (i = 2; i <= n; i++) {
ii = sorted_oil_v[i].second;
min_cost[ii] = INF;
for (j = 1; j<i; j++) {
jj = sorted_oil_v[j].second;
min_cost[ii] = min2(min_cost[ii], min_cost[jj] + shortest_d[jj][ii]);
}
}

return min_cost[n];
}
int main(void) {
int i, j;

input();

for (i = 1; i<n; i++) {
for (j = i + 1; j <= n; j++) {
shortest_d[i][j] = shortest_d[j][i] = INF;
}
dijkstra(i);
}

fprintf(fp2, "%lld\n", get_answer());
return 0;
}

Compilation message

gas.cpp: In function 'void input()':
gas.cpp:24:29: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 fscanf(fp1, "%d %d", &n, &m);
                             ^
gas.cpp:26:29: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 fscanf(fp1, "%d", &oil_v[i]);
                             ^
gas.cpp:28:43: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 fscanf(fp1, "%d %d %d", &v1, &v2, &weight);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 50168 KB Output is correct
2 Correct 0 ms 50168 KB Output is correct
3 Correct 0 ms 50168 KB Output is correct
4 Correct 0 ms 50168 KB Output is correct
5 Correct 0 ms 50168 KB Output is correct
6 Correct 0 ms 50168 KB Output is correct
7 Correct 0 ms 50168 KB Output is correct
8 Correct 0 ms 50168 KB Output is correct
9 Correct 0 ms 50168 KB Output is correct
10 Correct 0 ms 50168 KB Output is correct
11 Correct 0 ms 50168 KB Output is correct
12 Correct 0 ms 50168 KB Output is correct
13 Correct 0 ms 50168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 323 ms 50300 KB Output is correct
2 Correct 336 ms 50300 KB Output is correct
3 Correct 343 ms 50300 KB Output is correct
4 Correct 336 ms 50300 KB Output is correct
5 Correct 359 ms 50300 KB Output is correct
6 Correct 349 ms 50300 KB Output is correct
7 Correct 329 ms 50300 KB Output is correct
8 Correct 319 ms 50300 KB Output is correct
9 Correct 346 ms 50300 KB Output is correct
10 Correct 329 ms 50300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 50300 KB Output is correct
2 Correct 1159 ms 50436 KB Output is correct
3 Correct 1153 ms 50432 KB Output is correct
4 Correct 1149 ms 50432 KB Output is correct
5 Correct 1153 ms 50432 KB Output is correct
6 Correct 1346 ms 50432 KB Output is correct
7 Correct 1366 ms 50432 KB Output is correct
8 Correct 1336 ms 50432 KB Output is correct
9 Correct 1199 ms 50436 KB Output is correct
10 Correct 1186 ms 50436 KB Output is correct
11 Correct 1153 ms 50436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 50168 KB Output is correct
2 Correct 0 ms 50168 KB Output is correct
3 Correct 0 ms 50168 KB Output is correct
4 Correct 0 ms 50168 KB Output is correct
5 Correct 0 ms 50168 KB Output is correct
6 Correct 0 ms 50168 KB Output is correct
7 Correct 0 ms 50168 KB Output is correct
8 Correct 0 ms 50168 KB Output is correct
9 Correct 0 ms 50168 KB Output is correct
10 Correct 0 ms 50168 KB Output is correct
11 Correct 0 ms 50168 KB Output is correct
12 Correct 0 ms 50168 KB Output is correct
13 Correct 0 ms 50168 KB Output is correct
14 Correct 9 ms 50168 KB Output is correct
15 Correct 13 ms 50168 KB Output is correct
16 Correct 9 ms 50168 KB Output is correct
17 Correct 66 ms 50300 KB Output is correct
18 Correct 69 ms 50300 KB Output is correct
19 Correct 29 ms 50168 KB Output is correct
20 Correct 29 ms 50168 KB Output is correct
21 Correct 29 ms 50168 KB Output is correct
22 Correct 29 ms 50168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 50168 KB Output is correct
2 Correct 0 ms 50168 KB Output is correct
3 Correct 0 ms 50168 KB Output is correct
4 Correct 0 ms 50168 KB Output is correct
5 Correct 0 ms 50168 KB Output is correct
6 Correct 0 ms 50168 KB Output is correct
7 Correct 0 ms 50168 KB Output is correct
8 Correct 0 ms 50168 KB Output is correct
9 Correct 0 ms 50168 KB Output is correct
10 Correct 0 ms 50168 KB Output is correct
11 Correct 0 ms 50168 KB Output is correct
12 Correct 0 ms 50168 KB Output is correct
13 Correct 0 ms 50168 KB Output is correct
14 Correct 323 ms 50300 KB Output is correct
15 Correct 336 ms 50300 KB Output is correct
16 Correct 343 ms 50300 KB Output is correct
17 Correct 336 ms 50300 KB Output is correct
18 Correct 359 ms 50300 KB Output is correct
19 Correct 349 ms 50300 KB Output is correct
20 Correct 329 ms 50300 KB Output is correct
21 Correct 319 ms 50300 KB Output is correct
22 Correct 346 ms 50300 KB Output is correct
23 Correct 329 ms 50300 KB Output is correct
24 Correct 336 ms 50300 KB Output is correct
25 Correct 1159 ms 50436 KB Output is correct
26 Correct 1153 ms 50432 KB Output is correct
27 Correct 1149 ms 50432 KB Output is correct
28 Correct 1153 ms 50432 KB Output is correct
29 Correct 1346 ms 50432 KB Output is correct
30 Correct 1366 ms 50432 KB Output is correct
31 Correct 1336 ms 50432 KB Output is correct
32 Correct 1199 ms 50436 KB Output is correct
33 Correct 1186 ms 50436 KB Output is correct
34 Correct 1153 ms 50436 KB Output is correct
35 Correct 9 ms 50168 KB Output is correct
36 Correct 13 ms 50168 KB Output is correct
37 Correct 9 ms 50168 KB Output is correct
38 Correct 66 ms 50300 KB Output is correct
39 Correct 69 ms 50300 KB Output is correct
40 Correct 29 ms 50168 KB Output is correct
41 Correct 29 ms 50168 KB Output is correct
42 Correct 29 ms 50168 KB Output is correct
43 Correct 29 ms 50168 KB Output is correct
44 Correct 533 ms 50300 KB Output is correct
45 Correct 633 ms 50300 KB Output is correct
46 Correct 723 ms 50300 KB Output is correct
47 Correct 1159 ms 50432 KB Output is correct
48 Correct 1166 ms 50432 KB Output is correct
49 Correct 1043 ms 50432 KB Output is correct
50 Correct 1046 ms 50432 KB Output is correct
51 Correct 1053 ms 50432 KB Output is correct
52 Correct 1033 ms 50432 KB Output is correct