mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 23:38:47 +00:00
parent
62ffd92f58
commit
bcc7add1ea
84
LibreOJ/187/187.cpp
Normal file
84
LibreOJ/187/187.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 105,
|
||||
K = 12;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
|
||||
int n, m, k, a[K], f[1 << K][N], ans = INF;
|
||||
std::vector<std::pair<int, int>> g[N];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m >> k;
|
||||
|
||||
for (int i = 1, u, v, w; i <= m; i++) {
|
||||
cin >> u >> v >> w;
|
||||
|
||||
g[u].emplace_back(v, w);
|
||||
g[v].emplace_back(u, w);
|
||||
}
|
||||
|
||||
memset(f, 0x3f, sizeof(f));
|
||||
|
||||
for (int i = 1; i <= k; i++) {
|
||||
cin >> a[i];
|
||||
|
||||
f[1 << (i - 1)][a[i]] = 0;
|
||||
}
|
||||
|
||||
for (int s = 0; s < 1 << k; s++) {
|
||||
std::queue<int> q;
|
||||
std::vector<bool> vis(n + 1);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int t = s & (s - 1); t; t = (t - 1) & s) {
|
||||
f[s][i] = std::min(f[s][i], f[t][i] + f[s ^ t][i]);
|
||||
}
|
||||
|
||||
if (f[s][i] != INF) {
|
||||
q.emplace(i);
|
||||
vis[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// SPFA
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
|
||||
vis[u] = false;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
w = e.second;
|
||||
|
||||
if (f[s][v] > f[s][u] + w) {
|
||||
f[s][v] = f[s][u] + w;
|
||||
|
||||
if (!vis[v]) {
|
||||
q.emplace(v);
|
||||
vis[v] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= k; i++) {
|
||||
ans = std::min(ans, f[(1 << k) - 1][a[i]]);
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
LibreOJ/187/data/graph1.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph2.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph3.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph4.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph5.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph6.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph7.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph8.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph9.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/187/data/graph9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/187/data/graph9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user