# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
745929 |
2023-05-21T09:44:02 Z |
vjudge1 |
Cities (BOI16_cities) |
C++17 |
|
6000 ms |
136796 KB |
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
struct edge {
int to;
ll weight;
bool operator >(edge const& rhs) const {
return weight > rhs.weight;
}
};
vector<ll> dijkstra(vector<vector<edge>> const& graph, int const start) {
priority_queue<edge, vector<edge>, greater<edge>> pq;
vector<ll> dist(graph.size(), LLONG_MAX / 3);
dist[start] = 0;
pq.push({ start, 0 });
while (!pq.empty()) {
auto const [cur, cur_dist] = pq.top();
pq.pop();
if (cur_dist != dist[cur])
continue;
for (auto const& [neigh, weight] : graph[cur]) {
ll const new_dist = cur_dist + weight;
if (new_dist < dist[neigh]) {
dist[neigh] = new_dist;
pq.push({ neigh, new_dist });
}
}
}
return dist;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, m;
cin >> n >> k >> m;
vector<int> important(k);
for (int& x : important) {
cin >> x;
x--;
}
vector<vector<edge>> graph(n);
for (int i = 0; i < m; i++) {
int u, v;
ll w;
cin >> u >> v >> w;
u--; v--;
graph[u].push_back({ v, w });
graph[v].push_back({ u, w });
}
vector<vector<ll>> dist(n);
for (int i = 0; i < n; i++)
dist[i] = dijkstra(graph, i);
ll min_dist = LLONG_MAX / 3;
for (int a = 0; a < n - 1; a++) {
for (int b = a + 1; b < n; b++) {
ll cur_dist = dist[a][b];
for (int const& i : important) {
cur_dist += min(dist[a][i], dist[b][i]);
}
min_dist = min(min_dist, cur_dist);
}
}
cout << min_dist << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6048 ms |
131540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
8448 KB |
Output is correct |
2 |
Correct |
126 ms |
8268 KB |
Output is correct |
3 |
Correct |
48 ms |
8204 KB |
Output is correct |
4 |
Correct |
43 ms |
2308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6045 ms |
133664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6071 ms |
136796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |