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<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define int long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define NeedForSpeed ios::sync_with_stdio(0), cin.tie(0)
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
const int N = 1e5 + 12, INF = 1e18;
int n, m, k, a, b, c, d, s, f, l, r, x, y, z, res = INF, dis[505][505];
vector<pii> g[N];
vector<int> ds(N, INF), df(N, INF), dl(N, INF), dr(N, INF);
void dfs(int s, vector<int> &dis){
priority_queue<pii> q;
q.push({0, s});
dis[s] = 0;
//tin[s] = 0;
//g[x].pb({y, z});
//g[y].pb({x, z});
//dfs(f, df);
//dfs(l, dl);
//dfs(r, dr);
//dfs(s, ds);
while(!q.empty()){
int v = q.top().sc;
q.pop();
for(auto i : g[v]){
int to = i.fr, len = i.sc;
if(dis[v] + len < dis[to]){
dis[to] = min(dis[to], dis[v] + len);
q.push({dis[to], to});
//tin[to] = tin[v] + 1;
}
}
}
}
void solve(){
memset(dis, 63, sizeof dis);
cin>>n>>m;
cin>>s>>f;
cin>>l>>r;
for(int i=1; i<=m; i++){
cin>>x>>y>>z;
dis[x][y] = z;
dis[y][x] = z;
}
for(int i=1; i<=n; i++)dis[i][i] = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=1; k<=n; k++){
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dis[s][i] + dis[i][j] + dis[j][f] == dis[s][f]){
res = min(res, dis[l][i] + dis[j][r]);
res = min(res, dis[r][i] + dis[j][l]);
}
}
}
cout<<min(res, dis[l][r])<<"\n";
}
main(){
NeedForSpeed;
int T = 1;
// cin >> T;
while(T--){
solve();
}
return 0;
}
Compilation message (stderr)
commuter_pass.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | main(){
| ^~~~
# | 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... |