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;
using ll = long long;
#warning change mxn
const int mxn = 3e1+5;
const ll inf = 1e16;
struct Edge {
int to, id;
};
int n, m;
int A[mxn], B[mxn];
vector<Edge> adj[mxn];
ll W[mxn];
vector<ll> get_min_dist(int start, int forb) {
vector<long long> dist(n+1, inf);
priority_queue<pair<ll, int>> pq;
dist[start] = 0;
pq.push({-dist[start], start});;
while(!pq.empty()) {
ll d = -pq.top().first;
int a = pq.top().second;
pq.pop();
if(dist[a] != d) continue;
for(auto e : adj[a]) if(dist[e.to] > d+W[e.id] && e.id != forb) {
dist[e.to] = d+W[e.id];
pq.push({-dist[e.to], e.to});
}
}
return dist;
}
int main(int argc, char const *argv[]) {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> A[i] >> B[i] >> W[i];
adj[A[i]].push_back({B[i], i});
adj[B[i]].push_back({A[i], i});
}
vector<ll> from1, fromn;
from1 = get_min_dist(1, -1);
fromn = get_min_dist(n, -1);
ll mxw = W[m];
vector<ll> ans(m);
for(int i = m-1; i >= 1; i--) {
ll nw = W[i]+mxw;
ll mndist = inf;
mndist = min(mndist, from1[A[i]]+fromn[B[i]]+nw);
mndist = min(mndist, from1[B[i]]+fromn[A[i]]+nw);
ans[i] = mndist;
mxw = max(mxw, W[i]);
}
for(int i = m-1; i >= 1; i--) {
ans[i] = min(ans[i], get_min_dist(1, i)[n]);
}
ll answer = 0;
for(int i = 1; i < m; i++) {
answer = max(answer, ans[i]);
}
cout << answer << "\n";
return 0;
}
Compilation message (stderr)
Aesthetic.cpp:7:2: warning: #warning change mxn [-Wcpp]
7 | #warning change mxn
| ^~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |