# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
147819 | 2019-08-30T19:22:48 Z | luciocf | Cities (BOI16_cities) | C++14 | 341 ms | 24684 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pii; const int maxn = 2e5+10; const ll inf = 1e18+10; int n, cnt=-1; int a[6]; ll dist[3][maxn]; bool mark[maxn]; vector<pii> grafo[maxn]; void dijkstra(int s) { ++cnt; memset(mark, 0, sizeof mark); for (int i = 1; i <= n; i++) dist[cnt][i] = inf; priority_queue<pii, vector<pii>, greater<pii>> fila; dist[cnt][s] = 0, fila.push({0, s}); while (!fila.empty()) { int u = fila.top().second; fila.pop(); if (mark[u]) continue; mark[u] = 1; for (auto pp: grafo[u]) { int v = pp.first, w = pp.second; if (dist[cnt][v] > dist[cnt][u]+1ll*w) { dist[cnt][v] = dist[cnt][u]+1ll*w; fila.push({dist[cnt][v], v}); } } } } int main(void) { int m, k; scanf("%d %d %d", &n, &k, &m); for (int i = 1; i <= k; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { int u, v, w; scanf("%d %d %d", &u, &v, &w); grafo[u].push_back({v, w}); grafo[v].push_back({u, w}); } if (k == 2) { int u = a[1], v = a[2]; dijkstra(u); printf("%lld\n", dist[0][v]); } else { int u = a[1], v = a[2], w = a[3]; dijkstra(u); dijkstra(v); dijkstra(w); ll ans = inf; for (int i = 1; i <= n; i++) if (dist[0][i] != inf && dist[1][i] != inf && dist[2][i] != inf) ans = min(ans, dist[0][i]+dist[1][i]+dist[2][i]); printf("%lld\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5240 KB | Output is correct |
2 | Correct | 6 ms | 5240 KB | Output is correct |
3 | Correct | 6 ms | 5240 KB | Output is correct |
4 | Incorrect | 6 ms | 5240 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 317 ms | 24064 KB | Output is correct |
2 | Correct | 311 ms | 24684 KB | Output is correct |
3 | Correct | 145 ms | 14900 KB | Output is correct |
4 | Correct | 108 ms | 17752 KB | Output is correct |
5 | Correct | 221 ms | 21704 KB | Output is correct |
6 | Correct | 103 ms | 17656 KB | Output is correct |
7 | Correct | 8 ms | 5368 KB | Output is correct |
8 | Correct | 8 ms | 5368 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 5496 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 337 ms | 24084 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 341 ms | 24156 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |