#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e16;
vector<ll> dijsktra(vector<vector<pair<int, ll>>> v, int s){
int n = v.size();
vector<ll> dis(n, inf);
vector<bool> bl(n, 0);
priority_queue<pair<ll, int>> pq;
dis[s] = 0;
pq.push({0, s});
while(!pq.empty()){
int nd = pq.top().sc;
pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){
dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
return dis;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
int S, T, U, V; cin >> S >> T >> U >> V; S--, T--, U--, V--;
vector<vector<pair<int, ll>>> v(n);
for(int i = 0; i < m; i++){
int a, b; ll w; cin >> a >> b >> w; a--, b--;
v[a].pb({b, w});
v[b].pb({a, w});
}
vector<vector<ll>> d(n);
for(int i = 0; i < n; i++) d[i] = dijsktra(v, i);
ll ans = d[U][V];
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
if(d[S][i]+d[i][j]+d[T][j] == d[S][T]) ans = min(ans, min(d[U][i]+d[V][j], d[U][j]+d[V][i]));
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
55660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
53808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
3128 KB |
Output is correct |
2 |
Correct |
19 ms |
1196 KB |
Output is correct |
3 |
Correct |
22 ms |
1060 KB |
Output is correct |
4 |
Correct |
90 ms |
5028 KB |
Output is correct |
5 |
Correct |
54 ms |
3080 KB |
Output is correct |
6 |
Correct |
23 ms |
1152 KB |
Output is correct |
7 |
Correct |
26 ms |
1228 KB |
Output is correct |
8 |
Correct |
39 ms |
1284 KB |
Output is correct |
9 |
Correct |
25 ms |
1084 KB |
Output is correct |
10 |
Correct |
56 ms |
3300 KB |
Output is correct |
11 |
Correct |
9 ms |
1072 KB |
Output is correct |
12 |
Correct |
15 ms |
972 KB |
Output is correct |
13 |
Correct |
19 ms |
1080 KB |
Output is correct |
14 |
Correct |
25 ms |
1044 KB |
Output is correct |
15 |
Correct |
22 ms |
1068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
55660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |