题意:给你一副无向图,求使s到t删掉一条的最短路最大的长度
题解:先预处理s,t到每个点的最短路,二分答案,对于一条边,如果选中这条边,那么对于s->u+u->v+v->t或者s->v+v->u+v->t必须比二分的答案大,如果比二分的答案小,那么单独存下来对于这些不满足的边,我们看是否存在s到t的桥,如果有,那么我们删掉桥,就能使这些不满足的边都满足条件,复杂度O(log(mw)m)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("c.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
template<typename T>
inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>
inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}
using namespace std;
const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=1000000+10,inf=0x3f3f3f3f;
int n,m,s,t;
struct edge{
int to,Next,c;
}e[maxn];
int cnt,head[N];
ll dis[2][N];
pair<pair<int,int>,int>ee[maxn];
void init()
{
cnt=0;
memset(head,-1,sizeof head);
}
void add(int u,int v,int c)
{
e[cnt].to=v;
e[cnt].c=c;
e[cnt].Next=head[u];
head[u]=cnt++;
}
priority_queue<pli,vector<pli>,greater<pli>>q;
void dij(int s,int op)
{
memset(dis[op],INF,sizeof dis[op]);
dis[op][s]=0;
q.push(mp(dis[op][s],s));
while(!q.empty())
{
pli u=q.top();q.pop();
if(dis[op][u.se]<u.fi)continue;
for(int i=head[u.se];~i;i=e[i].Next)
{
int x=e[i].to;
if(dis[op][x]>dis[op][u.se]+e[i].c)
{
dis[op][x]=dis[op][u.se]+e[i].c;
q.push(mp(dis[op][x],x));
}
}
}
}
vi v[N];
int dfn[N],low[N],ind;
bool is[N],flag;
void tarjan(int u,int f)
{
dfn[u]=low[u]=++ind;
if(u==t)is[u]=1;
for(int i=0;i<v[u].size();i++)
{
int x=v[u][i];
if(x==f)continue;
if(!dfn[x])
{
tarjan(x,u);
low[u]=min(low[u],low[x]);
if(low[x]>dfn[u]&&!is[u]&&is[x])flag=1;
is[u]|=is[x];
}
else low[u]=min(low[u],dfn[x]);
}
}
bool ok(ll x)
{
memset(dfn,0,sizeof dfn);
memset(low,0,sizeof low);
memset(is,0,sizeof is);
for(int i=0;i<=n;i++)v[i].clear();
ind=0;flag=0;
for(int i=0;i<m;i++)
{
int a=ee[i].fi.fi,b=ee[i].fi.se,c=ee[i].se;
if(dis[0][a]+c+dis[1][b]<=x||dis[0][b]+c+dis[1][a]<=x)
v[a].pb(b),v[b].pb(a);
}
tarjan(s,-1);
return flag;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&t);
init();
for(int i=0;i<m;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);add(b,a,c);
ee[i]=mp(mp(a,b),c);
}
dij(s,0);dij(t,1);
ll l=dis[0][t]-1,r=9e9+1;
while(l<r-1)
{
ll m=(l+r)>>1;
if(ok(m))l=m;
else r=m;
}
printf("%lld
",r==9000000001?-1ll:r);
return 0;
}
/********************
3 3
1 3
1 2 1
2 3 1
1 3 1
********************/