#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define ALL(x) x.begin(),x.end()
#define random(l, r) (l + rand() % (r - l + 1))
#define int long long
#define maxn 300005
#define bit(x, i) ((x >> i) & 1)
#define pii pair<int, int>
#define MOD 1000000000000000007
#define Task "A"
using namespace std;
vector<pair<int, pii> > v[maxn];
vector<int> T[maxn],W[maxn];
int d1[maxn],dn[maxn], f[maxn], g[maxn],ea[maxn],eb[maxn],ec[maxn], par[maxn],path[maxn],wh[maxn];
multiset<pair<int,int> > S;
int n,m;
void ad(int x)
{
g[x] = 1;
for(auto E : v[x])
{
int y = E.F, l = E.S.F, u= E.S.S;
auto it= S.find({dn[y] + l + d1[x], u});
if(g[y] == 1) S.erase(it);
if(g[y] == 0) S.insert({dn[x] + l + d1[y], u});
}
}
void dfs(int x, int p)
{
if(path[x]) wh[x] = x;
else wh[x] = wh[p];
T[wh[x]].push_back(x);
for(int y : W[x])
{
dfs(y, x);
}
}
int A = 0;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Task".inp", "r"))
{
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> m;
for(int i = 0; i < m; i++)cin >> ea[i]>>eb[i]>>ec[i];
for(int i = m-1; i >= 0; i--)
{
int a = ea[i], b = eb[i], c = ec[i];
if(a != b)
{
v[a].push_back({b, {c,A}});
v[b].push_back({a, {c,A}});
}
A = max(A, c);
}
for(int i = 1; i <= n; i++)d1[i] = dn[i] = MOD;
d1[1] = 0;
dn[n] = 0;
priority_queue<pii > q;
q.push({0, 1});
while(q.size())
{
int x = q.top().S;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(auto E: v[x])
{
int y = E.F, l = E.S.F;
if(!f[y] && d1[y] > d1[x] + l)
{
d1[y] = d1[x] + l;
par[y] = x;
q.push({-d1[y], y});
}
}
}
q.push({0, n});
for(int i = 1; i <= n; i++)f[i] = 0;
while(q.size())
{
int x = q.top().S;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(auto E: v[x])
{
int y = E.F, l = E.S.F;
if(!f[y] && dn[y] > dn[x] + l)
{
dn[y] = dn[x] + l;
q.push({-dn[y], y});
}
}
}
int ans = d1[n];
int X = n;
while(1)
{
path[X] = 1;
if(X == 1) break;
X = par[X];
}
for(int i = 1; i <= n; i++)W[par[i]].push_back(i);
dfs(1,0);
int x = n;
while(1)
{
for(int y : T[x])ad(y);
if(x == 1) break;
x = par[x];
if(S.size() == 0) continue;
int U = S.begin()->F + S.begin()->S;
auto it = S.begin();
it++;
if(it != S.end()) U = min(U, it->F);
ans = max(ans, U);
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |