提交时间:2026-01-10 16:28:19
运行 ID: 39467
#include <iostream> #include <queue> #include <tuple> // C++11 required for std::tuple #include <utility> #include <vector> using namespace std; using i64 = long long; constexpr int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int k, m, s; cin >> k >> m >> s; vector<int> a(k + 1); for (int i = 1; i <= k; ++i) cin >> a[i]; int n = 1 << k; vector<vector<pair<int, int>>> graph(n); for (int i = 0; i < m; ++i) { int u, v, c; cin >> u >> v >> c; graph[u].emplace_back(v, c); graph[v].emplace_back(u, c); } priority_queue<pair<int, int>> node1; vector<int> dist(n, INF); // C++11: explicit type (original CTAD is C++17) vector<vector<vector<bool>>> vis(n, vector<vector<bool>>(k + 1, vector<bool>(k + 1, false))); // C++11 explicit nested vector dist[s] = 0; node1.emplace(0, s); while (!node1.empty()) { // Fix 1: Replace C++17 structured binding with .first/.second (C++11 compatible) pair<int, int> top_elem = node1.top(); node1.pop(); int dis = top_elem.first; int cur = top_elem.second; dis = -dis; // Fix 2: Range-based for loop + pair iteration (C++11 compatible) for (const pair<int, int>& edge : graph[cur]) { int nxt = edge.first; int cost = edge.second; if (!vis[nxt][0][0] && dist[nxt] > dist[cur] + cost) { dist[nxt] = dist[cur] + cost; node1.emplace(-dist[nxt], nxt); } } queue<tuple<int, int, int>> node2; node2.emplace(cur, 0, 0); while (!node2.empty()) { // Fix 3: Replace C++17 tuple structured binding with std::get (C++11 standard) tuple<int, int, int> front_elem = node2.front(); node2.pop(); int u = get<0>(front_elem); int i = get<1>(front_elem); int j = get<2>(front_elem); if (vis[u][i][j]) continue; vis[u][i][j] = true; if (i == k && !vis[u][0][0] && dist[u] > dis + a[j]) { dist[u] = dis + a[j]; node1.emplace(-dist[u], u); } else if (i < k) { node2.emplace(u, i + 1, j); node2.emplace(u ^ (1 << i), i + 1, j + 1); } } } for (int i = 0; i < n; ++i) cout << dist[i] << ' '; return 0; }