This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |