Submission #56961

# Submission time Handle Problem Language Result Execution time Memory
56961 2018-07-13T10:27:36 Z red1108 None (KOI16_gas) C++17
100 / 100
1589 ms 52884 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define P pair<long long int,long long int>
using namespace std;
typedef long long ll;
ll n,m;
ll cost[2510];
bool visit[2510];
ll dis[2510][2510];
vector<ll> graph[2510],dist[2510];
priority_queue<P,vector<P>, greater<P> >pq;
P now;
int main()
{
    ll i, j;
    ll a,b,c;
    scanf("%lld %lld", &n, &m);
    for(i=1;i<=n;i++) scanf("%lld", &cost[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%lld %lld %lld", &a, &b, &c);
        graph[a].push_back(b);
        graph[b].push_back(a);
        dist[a].push_back(c);
        dist[b].push_back(c);
    }
    for(i=1;i<=n;i++)
    {
        while(!pq.empty()) pq.pop();
        fill(visit+1,visit+n+1,0);
        pq.push({0,i});
        while(!pq.empty())
        {
            now=pq.top();
            pq.pop();
            if(visit[now.second]) continue;
            visit[now.second]=1;
            for(int to=0;to<graph[now.second].size();to++)
            {
                if((dis[i][graph[now.second][to]]==0||dis[i][graph[now.second][to]]>now.first+dist[now.second][to])&&graph[now.second][to]!=i)
                {
                    dis[i][graph[now.second][to]]=now.first+dist[now.second][to];
                    pq.push({now.first+dist[now.second][to],graph[now.second][to]});
                }
            }
        }
        for(j=1;j<=n;j++)
        {
            dis[i][j]*=cost[i];
        }
    }
    while(!pq.empty()) pq.pop();
    fill(visit+1,visit+n+1,0);
    pq.push({0,1});
    for(i=2;i<=n;i++)
    {
        pq.push({dis[1][i],i});
    }
    while(!pq.empty())
    {
        now=pq.top();
        pq.pop();
        if(visit[now.second]) continue;
        visit[now.second]=1;
        for(i=2;i<=n;i++)
        {
            if(dis[1][i]>now.first+dis[now.second][i])
            {
                dis[1][i]=now.first+dis[now.second][i];
                pq.push({now.first+dis[now.second][i],(ll)i});
            }
        }
    }

    printf("%lld", dis[1][n]);
}

Compilation message

gas.cpp: In function 'int main()':
gas.cpp:40:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int to=0;to<graph[now.second].size();to++)
                          ~~^~~~~~~~~~~~~~~~~~~~~~~~~
gas.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
gas.cpp:20:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++) scanf("%lld", &cost[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~
gas.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 572 KB Output is correct
2 Correct 2 ms 776 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1020 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
10 Correct 2 ms 1020 KB Output is correct
11 Correct 3 ms 1020 KB Output is correct
12 Correct 2 ms 1020 KB Output is correct
13 Correct 2 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 287 ms 50412 KB Output is correct
2 Correct 363 ms 50828 KB Output is correct
3 Correct 335 ms 51320 KB Output is correct
4 Correct 378 ms 51320 KB Output is correct
5 Correct 290 ms 51320 KB Output is correct
6 Correct 269 ms 51320 KB Output is correct
7 Correct 321 ms 51352 KB Output is correct
8 Correct 246 ms 51352 KB Output is correct
9 Correct 328 ms 51352 KB Output is correct
10 Correct 294 ms 51352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 51352 KB Output is correct
2 Correct 1254 ms 51352 KB Output is correct
3 Correct 1095 ms 51352 KB Output is correct
4 Correct 1088 ms 51352 KB Output is correct
5 Correct 1223 ms 51452 KB Output is correct
6 Correct 1589 ms 51468 KB Output is correct
7 Correct 1411 ms 51724 KB Output is correct
8 Correct 1473 ms 51724 KB Output is correct
9 Correct 1242 ms 51724 KB Output is correct
10 Correct 1240 ms 51748 KB Output is correct
11 Correct 1317 ms 51848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 572 KB Output is correct
2 Correct 2 ms 776 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1020 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
10 Correct 2 ms 1020 KB Output is correct
11 Correct 3 ms 1020 KB Output is correct
12 Correct 2 ms 1020 KB Output is correct
13 Correct 2 ms 1020 KB Output is correct
14 Correct 22 ms 51848 KB Output is correct
15 Correct 22 ms 51848 KB Output is correct
16 Correct 28 ms 51848 KB Output is correct
17 Correct 88 ms 51848 KB Output is correct
18 Correct 79 ms 51848 KB Output is correct
19 Correct 40 ms 51848 KB Output is correct
20 Correct 40 ms 51848 KB Output is correct
21 Correct 39 ms 51848 KB Output is correct
22 Correct 36 ms 51848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 572 KB Output is correct
2 Correct 2 ms 776 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1020 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
10 Correct 2 ms 1020 KB Output is correct
11 Correct 3 ms 1020 KB Output is correct
12 Correct 2 ms 1020 KB Output is correct
13 Correct 2 ms 1020 KB Output is correct
14 Correct 287 ms 50412 KB Output is correct
15 Correct 363 ms 50828 KB Output is correct
16 Correct 335 ms 51320 KB Output is correct
17 Correct 378 ms 51320 KB Output is correct
18 Correct 290 ms 51320 KB Output is correct
19 Correct 269 ms 51320 KB Output is correct
20 Correct 321 ms 51352 KB Output is correct
21 Correct 246 ms 51352 KB Output is correct
22 Correct 328 ms 51352 KB Output is correct
23 Correct 294 ms 51352 KB Output is correct
24 Correct 364 ms 51352 KB Output is correct
25 Correct 1254 ms 51352 KB Output is correct
26 Correct 1095 ms 51352 KB Output is correct
27 Correct 1088 ms 51352 KB Output is correct
28 Correct 1223 ms 51452 KB Output is correct
29 Correct 1589 ms 51468 KB Output is correct
30 Correct 1411 ms 51724 KB Output is correct
31 Correct 1473 ms 51724 KB Output is correct
32 Correct 1242 ms 51724 KB Output is correct
33 Correct 1240 ms 51748 KB Output is correct
34 Correct 1317 ms 51848 KB Output is correct
35 Correct 22 ms 51848 KB Output is correct
36 Correct 22 ms 51848 KB Output is correct
37 Correct 28 ms 51848 KB Output is correct
38 Correct 88 ms 51848 KB Output is correct
39 Correct 79 ms 51848 KB Output is correct
40 Correct 40 ms 51848 KB Output is correct
41 Correct 40 ms 51848 KB Output is correct
42 Correct 39 ms 51848 KB Output is correct
43 Correct 36 ms 51848 KB Output is correct
44 Correct 474 ms 52076 KB Output is correct
45 Correct 700 ms 52124 KB Output is correct
46 Correct 678 ms 52124 KB Output is correct
47 Correct 1300 ms 52420 KB Output is correct
48 Correct 1229 ms 52420 KB Output is correct
49 Correct 1157 ms 52884 KB Output is correct
50 Correct 1046 ms 52884 KB Output is correct
51 Correct 1006 ms 52884 KB Output is correct
52 Correct 996 ms 52884 KB Output is correct