#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
//typedef pair<pii,pii>pi2;
typedef array<int,6>pi2;
void solve(){
int n,m;
cin >> n >> m;
int a,b;
cin >> a >> b;
int s,t;
cin >> s >> t;
int adj[n+5][n+5];
memset(adj,-1,sizeof(adj));
int temp,temp2,temp3;
for(int x=1;x<=n;x++) adj[x][x]=0;
for(int x=0;x<m;x++){
cin >> temp >> temp2 >> temp3;
if(adj[temp][temp2]==-1||(temp3<adj[temp][temp2])){
adj[temp][temp2]=temp3;
adj[temp2][temp]=temp3;
}
}
for(int k=1;k<=n;k++){
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
if(adj[x][k]==-1||adj[k][y]==-1) continue;
if(adj[x][y]!=-1&&adj[x][y]<=adj[x][k]+adj[k][y]) continue;
adj[x][y]=adj[x][k]+adj[k][y];
}
}
}
int target=adj[a][b];
int best=adj[s][t];
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
int mini=min(adj[a][x]+adj[b][y],adj[a][y]+adj[b][x])+adj[x][y];
if(mini==target){
best=min({best,adj[x][s]+adj[y][t],adj[x][t]+adj[y][s]});
}
}
}
cout << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
149 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
1368 KB |
Output is correct |
2 |
Correct |
46 ms |
1168 KB |
Output is correct |
3 |
Correct |
40 ms |
1116 KB |
Output is correct |
4 |
Correct |
51 ms |
1908 KB |
Output is correct |
5 |
Correct |
44 ms |
1524 KB |
Output is correct |
6 |
Correct |
46 ms |
1176 KB |
Output is correct |
7 |
Correct |
48 ms |
1200 KB |
Output is correct |
8 |
Correct |
50 ms |
1112 KB |
Output is correct |
9 |
Correct |
45 ms |
1184 KB |
Output is correct |
10 |
Correct |
59 ms |
1524 KB |
Output is correct |
11 |
Correct |
27 ms |
1112 KB |
Output is correct |
12 |
Correct |
41 ms |
1168 KB |
Output is correct |
13 |
Correct |
41 ms |
1168 KB |
Output is correct |
14 |
Correct |
45 ms |
1312 KB |
Output is correct |
15 |
Correct |
46 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
149 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |