# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82417 | farukkastamonuda | Ferries (NOI13_ferries) | C++14 | 323 ms | 20360 KiB |
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 <bits/stdc++.h>
#define fi first
#define se second
#define lo long long
#define inf 1000000009
#define md 1000000007
#define li 100005
#define mp make_pair
#define pb push_back
#define mid (start+end)/2
using namespace std;
int n, m, x, y, z, d[li];
vector<int> v[li], t[li];
priority_queue< pair<int, int> > q;
void bfs(){
for(int i = 1; i < n; i ++) d[i] = inf;
q.push(mp(0, n));
while(! q.empty()){
pair<int, int> temp = q.top();
q.pop();
int cst = - temp.fi;
int seh = temp.se;
if(d[seh] != cst) continue;
if(seh == 1){
printf("%d\n", cst);
exit(0);
}
for(int i = 0; i < (int)v[seh].size(); i ++){
int ata = v[seh][i];
if( ( int ) t[ata].size() > 0){
int knr = t[ata].back();
t[ata].pop_back();
if(d[ata] > d[seh] + knr){
d[ata] = d[seh] + knr;
q.push(mp(- d[ata], ata));
}
}
}
}
}
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= m; i ++){
scanf("%d %d %d", &x, &y, &z);
v[y].pb(x);
t[x].pb(z);
}
for(int i = 1;i <= n; i ++){
sort(t[i].begin(), t[i].end());
}
bfs();
return 0;
}
Compilation message (stderr)
# | 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... |