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/extc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,m;
vector<int> roads[100005],rev[100005];
int best[100005];
bool check[100005];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i=1;i<=m;i++){
int a,b,c;
cin >> a >> b >> c;
roads[a].push_back(c);
rev[b].push_back(a);
}
for(int i=1;i<=n;i++){
best[i] = 2e9;
sort(roads[i].begin(),roads[i].end());
}
best[n] = 0;
priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;
pq.push({0,n});
while(pq.size()>0){
while(pq.size()>0 and check[pq.top()[1]]){
pq.pop();
}
if(pq.size()==0){
break;
}
int x = pq.top()[1];
pq.pop();
check[x] = true;
for(int i:rev[x]){
if(best[x]+roads[i].back()<best[i]){
best[i] = best[x]+roads[i].back();
pq.push({best[i],i});
}
roads[i].pop_back();
}
}
cout << best[1] << "\n";
return 0;
}
# | 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... |