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 fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int n, m;
void solve(){
cin >> n >> m;
vector<int> inc[n + 1], graph[n + 1];
vector<int> dis(n + 1, INT_MAX);
for(int i = 1; i <= m; ++i){
int u, v, c;
cin >> u >> v >> c;
graph[v].push_back(u);
inc[u].push_back(c);
}
for(int i = 1; i <= n; ++i)
sort(inc[i].begin(), inc[i].end());
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
pq.push({0, n});
dis[n] = 0;
while(!pq.empty()){
int cost = pq.top().first;
int node = pq.top().second;
pq.pop();
for(auto k : graph[node]){
if(dis[k] > cost + inc[k].back()){
dis[k] = cost + inc[k].back();
pq.push({dis[k], k});
}
inc[k].pop_back();
}
}
cout << dis[1] << "\n";
}
int main(){
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
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... |