#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
x += k;
x %= mod;
if(x < 0) x += mod;
}
void del(int &x, int k)
{
x -= k;
x %= mod;
if(x < 0) x += mod;
}
int n,m,d[2][maxn];
array<int,3> edge[maxn];
vii ke[maxn],adj[maxn];
int p[maxn];
void dij(int inp,int d[],int n)
{
fo(i,1,n) d[i] = inf;
d[inp] = 0;
priority_queue<pii,vii,greater<pii>> q;
q.push({0,inp});
while(q.size())
{
auto [du,u] = q.top();
q.pop();
if(d[u] != du) continue;
for(auto [v,w] : ke[u])
{
if(d[v] > d[u] + w)
{
d[v] = d[u] + w;
q.push({d[v],v});
}
}
}
}
int low[maxn],num[maxn],cnt;
vi bridge;
void dfs(int u)
{
low[u] = num[u] = ++cnt;
for(auto [v,idx] : adj[u])
{
if(!num[v])
{
dfs(v);
minimize(low[u],low[v]);
if(low[v] == num[v]) bridge.pb(idx);
}
else minimize(low[u],num[v]);
}
}
bool check(int val)
{
cnt = 0;
bridge.clear();
fo(i,1,n) adj[i].clear(),low[i] = num[i] = 0;
cnt = 0;
fo(i,1,m)
{
auto [u,v,w] = edge[i];
if(d[0][u] + w + d[1][v] < val) adj[u].pb(v,i);
if(d[1][u] + w + d[0][v] < val) adj[v].pb(u,i);
}
dfs(1);
for(int it : bridge)
{
auto [u,v,w] = edge[it];
if(d[0][u] + w + d[1][v] < val and d[0][u] + w + d[1][v] + p[it] >= val) return 1;
if(d[1][u] + w + d[0][v] < val and d[1][u] + w + d[0][v] + p[it] >= val) return 1;
}
return 0;
}
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fo(i,1,m)
{
int u,v,w;
cin >> u >> v >> w;
ke[u].pb(v,w);
ke[v].pb(u,w);
edge[i] = {u,v,w};
}
fod(i,m,1) p[i] = max(p[i + 1],edge[i + 1][2]);
dij(1,d[0],n);
dij(n,d[1],n);
int l = d[0][n],r = d[0][n] + p[1] + 5,ans = l;
while(l <= r)
{
int mid = l + r >> 1;
if(check(mid)) ans = mid,l = mid + 1;
else r = mid - 1;
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
Aesthetic.cpp:120:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
120 | main()
| ^~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
126 | freopen(name ".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... |