Submission #58657

# Submission time Handle Problem Language Result Execution time Memory
58657 2018-07-18T16:41:27 Z andy627 None (KOI16_gas) C++17
100 / 100
915 ms 2916 KB
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#define LL long long
#define pii pair<int,int>
#define pli pair<LL,int>
#define ff first
#define ss second
#define INF (LL)1e18
using namespace std;

int n,m;
pii oil[2555];
vector<pii> edge[2555];

LL dist[2555],ans[2555];
bool is_gone[2555];

priority_queue<pli,vector<pli>,greater<pli> > pq;

void dijkstra(int idx){
    for(int i=1;i<=n;i++) is_gone[i]=0;
    for(int i=1;i<=n;i++) dist[i]=INF;
    dist[oil[idx].ss]=0;

    is_gone[oil[idx].ss]=1; pq.push({0,oil[idx].ss});
    while(!pq.empty()){
        int v=pq.top().ss; pq.pop();

        for(int i=0;i<edge[v].size();i++){
            if(dist[edge[v][i].ff]>dist[v]+edge[v][i].ss){
                dist[edge[v][i].ff]=dist[v]+edge[v][i].ss;
                is_gone[edge[v][i].ff]=1;
                pq.push({dist[edge[v][i].ff],edge[v][i].ff});
            }
        }
    }
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&oil[i].ff);
        oil[i].ss=i;
    }
    sort(oil+1,oil+n+1);

    while(m--){
        int a,b,w;
        scanf("%d %d %d",&a,&b,&w);
        edge[a].push_back({b,w});
        edge[b].push_back({a,w});
    }

    for(int i=1;i<=n;i++) ans[i]=INF;
    ans[1]=0;

    bool st=0;
    for(int i=n;i>=1;i--){
        if(oil[i].ss==1) st=1;
        if(!st) continue;

        dijkstra(i);

        for(int j=1;j<=n;j++){
            if(j==oil[i].ss) continue;
            ans[j]=min(ans[j],ans[oil[i].ss]+oil[i].ff*dist[j]);
        }
    }

    printf("%lld",ans[n]);

    return 0;
}

Compilation message

gas.cpp: In function 'void dijkstra(int)':
gas.cpp:31:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<edge[v].size();i++){
                     ~^~~~~~~~~~~~~~~
gas.cpp: In function 'int main()':
gas.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
gas.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&oil[i].ff);
         ~~~~~^~~~~~~~~~~~~~~~~
gas.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&a,&b,&w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 700 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 2 ms 836 KB Output is correct
11 Correct 3 ms 836 KB Output is correct
12 Correct 2 ms 836 KB Output is correct
13 Correct 3 ms 836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 904 KB Output is correct
2 Correct 228 ms 1056 KB Output is correct
3 Correct 261 ms 1144 KB Output is correct
4 Correct 203 ms 1144 KB Output is correct
5 Correct 80 ms 1252 KB Output is correct
6 Correct 30 ms 1252 KB Output is correct
7 Correct 121 ms 1260 KB Output is correct
8 Correct 159 ms 1404 KB Output is correct
9 Correct 100 ms 1404 KB Output is correct
10 Correct 4 ms 1416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1468 KB Output is correct
2 Correct 9 ms 1656 KB Output is correct
3 Correct 7 ms 1752 KB Output is correct
4 Correct 8 ms 1800 KB Output is correct
5 Correct 7 ms 1868 KB Output is correct
6 Correct 7 ms 2056 KB Output is correct
7 Correct 6 ms 2140 KB Output is correct
8 Correct 6 ms 2140 KB Output is correct
9 Correct 7 ms 2140 KB Output is correct
10 Correct 6 ms 2144 KB Output is correct
11 Correct 5 ms 2232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 700 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 2 ms 836 KB Output is correct
11 Correct 3 ms 836 KB Output is correct
12 Correct 2 ms 836 KB Output is correct
13 Correct 3 ms 836 KB Output is correct
14 Correct 12 ms 2232 KB Output is correct
15 Correct 7 ms 2232 KB Output is correct
16 Correct 9 ms 2232 KB Output is correct
17 Correct 50 ms 2232 KB Output is correct
18 Correct 82 ms 2312 KB Output is correct
19 Correct 35 ms 2312 KB Output is correct
20 Correct 29 ms 2312 KB Output is correct
21 Correct 29 ms 2312 KB Output is correct
22 Correct 40 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 700 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 2 ms 836 KB Output is correct
11 Correct 3 ms 836 KB Output is correct
12 Correct 2 ms 836 KB Output is correct
13 Correct 3 ms 836 KB Output is correct
14 Correct 6 ms 904 KB Output is correct
15 Correct 228 ms 1056 KB Output is correct
16 Correct 261 ms 1144 KB Output is correct
17 Correct 203 ms 1144 KB Output is correct
18 Correct 80 ms 1252 KB Output is correct
19 Correct 30 ms 1252 KB Output is correct
20 Correct 121 ms 1260 KB Output is correct
21 Correct 159 ms 1404 KB Output is correct
22 Correct 100 ms 1404 KB Output is correct
23 Correct 4 ms 1416 KB Output is correct
24 Correct 5 ms 1468 KB Output is correct
25 Correct 9 ms 1656 KB Output is correct
26 Correct 7 ms 1752 KB Output is correct
27 Correct 8 ms 1800 KB Output is correct
28 Correct 7 ms 1868 KB Output is correct
29 Correct 7 ms 2056 KB Output is correct
30 Correct 6 ms 2140 KB Output is correct
31 Correct 6 ms 2140 KB Output is correct
32 Correct 7 ms 2140 KB Output is correct
33 Correct 6 ms 2144 KB Output is correct
34 Correct 5 ms 2232 KB Output is correct
35 Correct 12 ms 2232 KB Output is correct
36 Correct 7 ms 2232 KB Output is correct
37 Correct 9 ms 2232 KB Output is correct
38 Correct 50 ms 2232 KB Output is correct
39 Correct 82 ms 2312 KB Output is correct
40 Correct 35 ms 2312 KB Output is correct
41 Correct 29 ms 2312 KB Output is correct
42 Correct 29 ms 2312 KB Output is correct
43 Correct 40 ms 2312 KB Output is correct
44 Correct 189 ms 2416 KB Output is correct
45 Correct 158 ms 2428 KB Output is correct
46 Correct 119 ms 2504 KB Output is correct
47 Correct 497 ms 2692 KB Output is correct
48 Correct 262 ms 2884 KB Output is correct
49 Correct 522 ms 2884 KB Output is correct
50 Correct 480 ms 2884 KB Output is correct
51 Correct 394 ms 2888 KB Output is correct
52 Correct 915 ms 2916 KB Output is correct