#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
int n, m;
int s, t, u, v;
vector<vector<pair<int, int>>> adj;
vector<vector<int>> p;
set<int> path;
void path_finder(int start) {
path.insert(start);
if (start == s)
return;
for (auto x : p[start]) {
path_finder(x);
}
}
void dijkstras(vector<vector<int>> &parent, vector<long long> &dist, int start) {
priority_queue<pair<int, int>> pq;
pq.push({0, start});
while (!pq.empty()) {
int x = pq.top().second;
pq.pop();
for (auto e : adj[x]) {
int w = e.second;
if (w + dist[x] < dist[e.first]) {
parent[e.first].push_back(x);
dist[e.first] = dist[x]+w;
pq.push({-dist[e.first], e.first});
}
}
}
}
int main() {
cin >> n >> m;
adj.resize(n+1);
p.resize(n+1);
cin >> s >> t >> u >> v;
for (int i = 0; i < m; i++) {
int x, y, w;
cin >> x >> y >> w;
adj[x].push_back({y, w});
adj[y].push_back({x, w});
}
p[s].push_back(s);
vector<long long> d(n+1, INF);
d[s] = 0;
dijkstras(p, d, s);
bool done = false;
for (auto x : p[t]) {
path_finder(x);
}
vector<vector<int>> temp(n+1);
vector<int> from_v(n+1);
vector<long long> dv(n+1, INF);
dv[v] = 0;
dijkstras(temp, dv, v);
long long ans = INF;
long long mnv = INF;
for (auto node : path) {
mnv = min(mnv, dv[node]);
ans = min(ans, mnv);
}
cout << ans << '\n';
return 0;
}
Compilation message
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:53:10: warning: unused variable 'done' [-Wunused-variable]
53 | bool done = false;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
21892 KB |
Output is correct |
2 |
Correct |
281 ms |
21800 KB |
Output is correct |
3 |
Execution timed out |
2083 ms |
15268 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2021 ms |
15260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
21892 KB |
Output is correct |
2 |
Correct |
281 ms |
21800 KB |
Output is correct |
3 |
Execution timed out |
2083 ms |
15268 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |