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>
using namespace std;
#define int long long
const int INF = (int)1e18;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n , m;
cin >> n >> m;
vector<vector<pair<int , int>>> adj(n) , rev(n);
vector<vector<int>> edges(n);
for (int i = 0 ; i < m ; i += 1) {
int a , b , c;
cin >> a >> b >> c;
a -= 1 , b -= 1;
edges[a].push_back(c);
adj[a].emplace_back(b , c);
rev[b].emplace_back(a , c);
}
for (int i = 0 ; i < n ; i += 1) {
sort(edges[i].begin() , edges[i].end());
}
#define pi pair<int , int>
priority_queue<pi , vector<pi> , greater<pi>> pq;
vector<int> d(n , INF);
d[n - 1] = 0;
pq.emplace(d[n - 1] , n - 1);
while (!pq.empty()) {
auto t = pq.top();
pq.pop();
if (d[t.second] != t.first) continue;
for (int i = 0 ; i < (int)rev[t.second].size() ; i += 1) {
auto node = rev[t.second][i];
if (d[node.first] > t.first + edges[node.first].back()) {
d[node.first] = t.first + edges[node.first].back();
pq.emplace(d[node.first] , node.first);
edges[node.first].pop_back();
}
}
}
cout << d[0] << '\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... |