Submission #38112

#TimeUsernameProblemLanguageResultExecution timeMemory
38112shash42Ferries (NOI13_ferries)C++11
40 / 40
803 ms28872 KiB
#include<iostream> #include<algorithm> #include<vector> #include<queue> #define pii pair<int, int> #define pb push_back #define mp make_pair using namespace std; struct indij { int dest, w, e; }; struct nsort { bool operator()(const indij &a, const indij &b) { if(a.w==b.w) return a.dest>b.dest; return a.w>b.w; } }; struct desc { bool operator()(const int &a, const int &b) { return a>b; } }; priority_queue<indij, vector<indij>, nsort> pq; int n, m, ptr[100005], visited[100005], rd[100005], edge[300005], d[100005]; vector< pii > radj[100005]; vector<int> wts[100005]; void dijkstra(int node) { //cout << node << endl; visited[node]=1; for(int i = 0; i < radj[node].size(); i++) { int child=radj[node][i].first; int ej=radj[node][i].second; if(edge[ej]==-1) { indij nxt; nxt.dest=child; edge[ej]=wts[nxt.dest][ptr[nxt.dest]++]; nxt.w=rd[node]+edge[ej]; nxt.e=ej; pq.push(nxt); } } int nxt=-1; while(pq.size()>0) { if(visited[pq.top().dest]==0) { nxt=pq.top().dest; rd[nxt]=pq.top().w; pq.pop(); break; } pq.pop(); } if(nxt!=-1) dijkstra(nxt); } int main() { cin >> n >> m; for(int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; radj[v].pb(mp(u, i)); wts[u].pb(w); edge[i]=-1; } for(int i = 1; i <= n; i++) { sort(wts[i].begin(), wts[i].end(), desc()); } rd[n]=0; dijkstra(n); cout << rd[1]; }

Compilation message (stderr)

ferries.cpp: In function 'void dijkstra(int)':
ferries.cpp:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < radj[node].size(); i++)
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...