# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
38112 |
2018-01-01T07:47:21 Z |
shash42 |
Ferries (NOI13_ferries) |
C++11 |
|
803 ms |
28872 KB |
#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
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 |
1 |
Correct |
0 ms |
9440 KB |
Output is correct |
2 |
Correct |
3 ms |
9572 KB |
Output is correct |
3 |
Correct |
26 ms |
11344 KB |
Output is correct |
4 |
Correct |
343 ms |
28872 KB |
Output is correct |
5 |
Correct |
376 ms |
28868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9440 KB |
Output is correct |
2 |
Correct |
0 ms |
9572 KB |
Output is correct |
3 |
Correct |
29 ms |
11380 KB |
Output is correct |
4 |
Correct |
153 ms |
19136 KB |
Output is correct |
5 |
Correct |
256 ms |
25408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
11112 KB |
Output is correct |
2 |
Correct |
46 ms |
11124 KB |
Output is correct |
3 |
Correct |
626 ms |
26416 KB |
Output is correct |
4 |
Correct |
719 ms |
26800 KB |
Output is correct |
5 |
Correct |
683 ms |
26800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
619 ms |
26432 KB |
Output is correct |
2 |
Correct |
679 ms |
26428 KB |
Output is correct |
3 |
Correct |
759 ms |
28048 KB |
Output is correct |
4 |
Correct |
803 ms |
28056 KB |
Output is correct |
5 |
Correct |
686 ms |
28064 KB |
Output is correct |