Submission #5042

#TimeUsernameProblemLanguageResultExecution timeMemory
5042cki86201Ferries (NOI13_ferries)C++98
40 / 40
252 ms17428 KiB
#include<stdio.h> #include<queue> using namespace std; typedef pair<int,int> Pi; #define X first #define Y second priority_queue <int> edge[100010]; priority_queue <Pi, vector<Pi>, greater<Pi> >pq; int st[100010], en[600060], nxt[600060], len[600060]; void add(int s,int e,int l,int c){nxt[c]=st[s],st[s]=c,en[c]=e,len[c]=l;} int dis[100010]; bool chk[100010]; int main() { int n, m; scanf("%d%d",&n,&m); int i; for(i=1;i<=m;i++){ int x, y, z; scanf("%d%d%d",&x,&y,&z); add(y,x,z,i); edge[x].push(z); } pq.push(Pi(0,n)); while(!pq.empty()){ Pi tmp = pq.top(); pq.pop(); if(chk[tmp.Y])continue; chk[tmp.Y] = 1; dis[tmp.Y] = tmp.X; for(i=st[tmp.Y];i;i=nxt[i]){ if(chk[en[i]])continue; pq.push(Pi(edge[en[i]].top() + tmp.X, en[i])); edge[en[i]].pop(); } } printf("%d",dis[1]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...