Submission #89995

# Submission time Handle Problem Language Result Execution time Memory
89995 2018-12-19T14:30:42 Z thebes Ferries (NOI13_ferries) C++14
28 / 40
388 ms 32976 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 1e5+5;
int N, M, i, x, y, W, dist[MN], idx[MN], vis[MN];
vector<int> adj[MN], w[MN];

typedef pair<int,int> pii;
struct pq{bool operator()(const pii&i,const pii&j){return i.second>j.second;}};
priority_queue<pii,vector<pii>,pq> q;

int main(){
    for(scanf("%d%d",&N,&M),i=1;i<=M;i++){
        scanf("%d%d%d",&x,&y,&W);
        adj[y].push_back(x);
        w[x].push_back(W);
    }
    for(i=1;i<=N;i++) sort(w[i].begin(),w[i].end(),[](int i,int j){return i>j;});
    memset(dist,0x3f,sizeof(dist));
    q.push({N,0});
    while(q.size()){
        auto v=q.top(); q.pop();
        if(vis[v.first]) continue;
        else dist[v.first]=v.second,vis[v.first]=1;
        for(auto e : adj[v.first]){
            W = w[e][idx[e]];
            if(!vis[e]&&W+v.second<dist[e]){
                idx[e]++;
                q.push({e, W+v.second});
            }
        }
    }
    printf("%d\n",dist[1]);
    return 0;
}

Compilation message

ferries.cpp: In function 'int main()':
ferries.cpp:13:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d",&N,&M),i=1;i<=M;i++){
         ~~~~~~~~~~~~~~~~~~~^~~~
ferries.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&W);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5500 KB Output is correct
2 Correct 7 ms 5624 KB Output is correct
3 Correct 18 ms 6860 KB Output is correct
4 Correct 139 ms 17492 KB Output is correct
5 Correct 140 ms 19380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 19380 KB Output is correct
2 Correct 7 ms 19380 KB Output is correct
3 Correct 17 ms 19380 KB Output is correct
4 Correct 81 ms 19380 KB Output is correct
5 Correct 140 ms 19380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19380 KB Output is correct
2 Correct 24 ms 19380 KB Output is correct
3 Correct 286 ms 19380 KB Output is correct
4 Correct 305 ms 19380 KB Output is correct
5 Correct 337 ms 22908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 22908 KB Output is correct
2 Correct 344 ms 27428 KB Output is correct
3 Runtime error 388 ms 32976 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
4 Halted 0 ms 0 KB -