This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;
int n, m, s, t, x, y;
ll d[N];
vector<array<ll, 3>> g[N];
vector<bool> vis;
vector<pair<int, int>> good;
void solve(){
cin >> n >> m >> s >> t >> x >> y;
for(int i = 0; i < m; ++i){
int u, v, w; cin >> u >> v >> w;
g[u].pb({v, w, i});
g[v].pb({u, w, i});
}
vis.resize(n + 1);
good.resize(m);
priority_queue<pair<ll, int>> q;
q.push({0, s});
for(int i = 1; i <= n; ++i) d[i] = i == s ? 0 : LONG_LONG_MAX;
while(!q.empty()){
int v = q.top().second; q.pop();
if(vis[v]) continue;
vis[v] = 1;
for(auto U: g[v]){
int u = U[0], w = U[1];
if(!vis[u] && d[u] > d[v] + w){
d[u] = d[v] + w;
q.push({-d[u], u});
}
}
}
queue<int> Q;
Q.push(t);
fill(all(vis), 0);
while(!Q.empty()){
int v = Q.front(); Q.pop();
for(auto U: g[v]){
int u = U[0], w = U[1];
if(!vis[u] && d[u] == d[v] - w){
vis[u] = 1;
good[U[2]] = {u, v};
Q.push(u);
}
}
}
for(int i = 1; i <= n; ++i) d[i] = LONG_LONG_MAX;
d[x] = 0;
q.push({0, x});
fill(all(vis), 0);
while(!q.empty()){
int v = q.top().second; q.pop();
if(vis[v]) continue;
vis[v] = 1;
for(auto U: g[v]){
int u = U[0], w = U[1];
if(good[U[2]].first == u && good[U[2]].second == v) w = 0;
if(!vis[u] && d[u] > d[v] + w){
d[u] = d[v] + w;
q.push({-d[u], u});
}
}
}
cout << d[y];
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:80:14: warning: unused variable 'aa' [-Wunused-variable]
80 | int T = 1, aa;
| ^~
# | 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... |