# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
968820 | blackslex | Cities (BOI16_cities) | C++17 | 859 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
int n, m, k, x, y;
ll z;
int main() {
scanf("%d %d %d", &n, &k, &m);
vector<int> c(k);
vector<vector<pii>> v(n + 5, vector<pii>());
for (auto &e: c) scanf("%d", &e);
vector<vector<ll>> d(n + 5, vector<ll>(n + 5, 1e18));
for (int i = 1; i <= n; i++) d[i][i] = 0;
while (m--) scanf("%d %d %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z), d[x][y] = d[y][x] = z;
for (int l = 1; l <= n; l++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
ll ans = 1e18;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int msk = 0; msk < (1 << k); msk++) {
ll cur = d[i][j];
for (int t = 0; t < k; t++) {
if (msk & (1 << t)) cur += d[i][c[t]];
else cur += d[j][c[t]];
}
ans = min(ans, cur);
}
}
}
printf("%lld", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |