이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
//#include <grader.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
#define db double
using namespace std;
const int N = 1e5 + 10;
int n, k, m;
ll dp[N][32];
int city[5];
vector<pll> adj[N];
priority_queue<pll> pq;
void solve() {
int n, k, m;cin >> n >> k >> m;
for (int s = 0; s < (1<<k); ++s) for (int i = 1; i <= n; ++i) dp[i][s] = 1e18;
for (int i = 0, u; i < k; ++i) {
cin >> u;
dp[u][(1<<i)] = 0;
}
for (int i = 1; i <= m; ++i) {
int u, v, w; cin >> u >> v >> w;
adj[u].pb({v, w}); adj[v].pb({u, w});
}
for (int s = 1; s < (1<<k); ++s) {
for (int j = 0; j < k; ++j) {
if (s&(1<<j))
for (int i = 1; i <= n; ++i)
dp[i][s] = min(dp[i][s], dp[i][(1<<j)] + dp[i][s^(1<<j)]);
}
for (int i = 1; i <= n; ++i) pq.push({-dp[i][s], i});
while (!pq.empty()) {
int a = pq.top().nd; pq.pop();
for (auto [b, w] : adj[a]) {
if (dp[b][s] > dp[a][s] + w) {
dp[b][s] = dp[a][s] + w;
pq.push({-dp[b][s], b});
}
}
}
}
ll ans = LLONG_MAX;
for (int i = 1; i <= n; ++i) ans = min(ans, dp[i][(1<<k)-1]);
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cities.cpp: In function 'void solve()':
cities.cpp:44:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for (auto [b, w] : adj[a]) {
| ^
# | 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... |