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>
using namespace std;
#define N 300005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
ll T, n, m, s, t, u1, u2, dis[N], a[N], b[N], c[N];
vector <pair<int,int>> v[N];
map <pair<int,int>, bool> vis;
void dfs(int x){
for(auto i : v[x]){
if(dis[x] == dis[i.ff] + i.ss){
vis[{x,i.ff}] = 1;
vis[{i.ff,x}] = 1;
dfs(i.ff);
return;
}
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> s >> t >> u1 >> u2;
for(int i = 1; i <= m; i++){
cin >> a[i] >> b[i] >> c[i];
v[a[i]].push_back({b[i],c[i]});
v[b[i]].push_back({a[i],c[i]});
}
for(int i = 1; i <= n; i++) dis[i] = 1e15;
priority_queue <pair<ll,ll>> q;
q.push({0,s});
dis[s] = 0;
while(!q.empty()){
int x = q.top().ss;
if(dis[x] != -q.top().ff){
q.pop();
continue;
}
q.pop();
for(auto i : v[x]){
if(dis[i.ff] > dis[x] + i.ss){
dis[i.ff] = dis[x] + i.ss;
q.push({-dis[i.ff], i.ff});
}
}
}
dfs(t);
for(int i = 1; i <= n; i++) v[i].clear();
for(int i = 1; i <= m; i++){
if(vis[{a[i],b[i]}] == 0){
v[a[i]].push_back({b[i],c[i]});
v[b[i]].push_back({a[i],c[i]});
}
else {
v[a[i]].push_back({b[i],0});
v[b[i]].push_back({a[i],0});
}
}
for(int i = 1; i <= n; i++) dis[i] = 1e15;
q.push({0,u1});
dis[u1] = 0;
while(!q.empty()){
int x = q.top().ss;
if(dis[x] != -q.top().ff){
q.pop();
continue;
}
q.pop();
for(auto i : v[x]){
if(dis[i.ff] > dis[x] + i.ss){
dis[i.ff] = dis[x] + i.ss;
q.push({-dis[i.ff], i.ff});
}
}
}
cout << dis[u2];
return 0;
}
# | 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... |