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>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag=false;
if(x>y){
x=y;flag|=true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag=false;
if (x<y){
x=y;flag|=true;
}
return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
vector<vector<pair<ll,ll>>> g(N);
vector<vector<ll>> g2(N);
ll i,j,n,m,u,v,s,t;
ll d[N];
bool f[N];
void bfs(ll st){
set<pair<ll,ll>> q;
for(i=1;i<=n;i++)d[i]=inf;
d[st]=0;
q.ins({d[st],st});
while(q.sz){
ll x=q.begin()->sc;
q.erase(q.begin());
for(auto i : g[x]){
if(d[i.fr]>d[x]+i.sc){
d[i.fr]=d[x]+i.sc;
q.ins({d[i.fr],i.fr});
}
}
}
}
void ba(ll st){
queue<ll> q;
q.push(st);
f[st]=true;
while(q.sz){
ll x=q.front();
q.pop();
for(auto i : g[x]){
if(d[i.fr]==d[x]-i.sc){
g2[i.fr].pb(x);
if(!f[i.fr])q.push(i.fr);
f[i.fr]=true;
}
}
}
}
ll dp[N][2];
void solve(){
cin>>n>>m;
cin>>s>>t;
cin>>u>>v;
ll a,b,c;
for(i=0;i<m;i++){
cin>>a>>b>>c;
g[a].pb({b,c});
g[b].pb({a,c});
}
bfs(s);
ba(t);
bfs(u);
set<pair<ll,ll>> q;
for(i=1;i<=n;i++)dp[i][0]=inf;
dp[s][0]=d[s];
q.ins({dp[s][0],s});
while(q.sz){
ll x=q.begin()->sc;
q.erase(q.begin());
for(auto i : g2[x]){
if(dp[i][0]>min(dp[x][0],d[i])){
dp[i][0]=min(dp[x][0],d[i]);
q.ins({dp[i][0],i});
}
}
}
for(i=1;i<=n;i++)dp[i][0]=min(dp[i][0],d[i]);
bfs(v);
for(i=1;i<=n;i++)dp[i][1]=inf;
dp[s][1]=d[s];
q.ins({dp[s][1],s});
while(q.sz){
ll x=q.begin()->sc;
q.erase(q.begin());
for(auto i : g2[x]){
if(dp[i][1]>min(dp[x][1],d[i])){
dp[i][1]=min(dp[x][1],d[i]);
q.ins({dp[i][1],i});
}
}
}
for(i=1;i<=n;i++)dp[i][1]=min(dp[i][1],d[i]);
ll ans=inf;
for(i=1;i<=n;i++){
cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
ans=min(ans,dp[i][0]+dp[i][1]);
}
cout<<ans<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message (stderr)
commuter_pass.cpp: In function 'void fre(std::string)':
commuter_pass.cpp:41:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:41:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"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... |