# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
310327 | BeanZ | Cities (BOI16_cities) | C++14 | 2513 ms | 44868 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
ll dp[(1 << 5) + 1][N], p[N];
vector<pair<ll, ll>> node[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, k, m;
cin >> n >> k >> m;
for (int i = 0; i < (1 << k); i++){
for (int j = 1; j <= n; j++){
dp[i][j] = 1e18;
}
}
for (int i = 0; i < k; i++) cin >> p[i], dp[(1 << i)][p[i]] = 0;
for (int i = 1; i <= m; i++){
ll u, v, c;
cin >> u >> v >> c;
node[u].push_back({v, c});
node[v].push_back({u, c});
}
for (int i = 1; i < (1 << k); i++){
ll now = -1;
for (int j = 0; j < k; j++){
if (!(i & (1 << j))) continue;
now = j;
break;
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
for (int j = 1; j <= n; j++){
if (now != -1) dp[i][j] = min(dp[i][j], dp[i ^ (1 << now)][j] + dp[(1 << now)][j]);
pq.push({dp[i][j], j});
}
while (pq.size()){
pair<ll, ll> x = pq.top();
pq.pop();
if (x.first != dp[i][x.second]) continue;
for (auto j : node[x.second]){
if ((x.first + j.second) < dp[i][j.first]){
dp[i][j.first] = x.first + j.second;
pq.push({dp[i][j.first], j.first});
}
}
}
}
ll ans = 1e18;
for (int i = 1; i <= n; i++){
ans = min(ans, dp[(1 << k) - 1][i]);
}
cout << 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... |