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>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll
const int MAX=1e5+15;
const int B=2e5;
const int N=104;
const int block=450;
const int maxB=MAX/B+10;
const ll inf=1e18;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1);
int k=binpow(a,n/2);
return k*k;
}
int n,m;
int s,t,u,v;
int dv[MAX],du[MAX],ds[MAX],dt[MAX];
vector<pii> g[MAX];
void calc(int (&d)[],int st){
for(int i=1;i<=n;i++)d[i]=inf;
d[st]=0;
set<pii> q;
q.in({0,st});
while(!q.empty()){
int v=q.begin()->S;
q.erase(q.begin());
for(auto to:g[v]){
if(d[to.F]>d[v]+to.S){
q.erase({d[to.F],to.F});
d[to.F]=d[v]+to.S;
q.in({d[to.F],to.F});
}
}
}
// cout<<st<<"\n";
// for(int i=1;i<=n;i++)cout<<d[i]<<" ";
// cout<<"\n";
}
int d[MAX];
int solve(int u,int v){
calc(dv,v);
calc(du,u);
calc(ds,s);
calc(dt,t);
int ans=du[v];
// cout<<du[v]<<"\n";
set<pii> q;
for(int i=1;i<=n;i++){
if(ds[i]+dt[i]==ds[t]){
d[i]=dv[i];
q.in({d[i],i});
}
else d[i]=inf;
}
while(!q.empty()){
int v=q.begin()->S;
q.erase(q.begin());
for(auto to:g[v]){
if(ds[to.F]+to.S+dt[v]==ds[t]){
if(d[to.F]>d[v]){
q.erase({d[to.F],to.F});
d[to.F]=d[v];
q.in({d[to.F],to.F});
}
}
}
}
for(int i=1;i<=n;i++){
// cout<<du[i]<<" "<<d[i]<<"\n";
if(ds[i]+dt[i]==ds[t]){
ans=min(ans,du[i]+d[i]);
}
}
return ans;
}
void solve(){
cin>>n>>m;
cin>>s>>t>>u>>v;
for(int i=1;i<=m;i++){
int x,y,z;
cin>>x>>y>>z;
g[x].pb({y,z});
g[y].pb({x,z});
// cout<<x<<" "<<y<<" "<<z<<"\n";
}
// cout<<solve(u,v)<<" "<<solve(v,u)<<"\n";
int ans=min(solve(u,v),solve(v,u));
cout<<ans;
// solve(u,v);
}
//1010
//0011
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// prec();
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message (stderr)
commuter_pass.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("Ofast")
|
commuter_pass.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
# | 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... |