diff --git a/S2OJ/161/161.cpp b/S2OJ/161/161.cpp new file mode 100644 index 00000000..aad82db2 --- /dev/null +++ b/S2OJ/161/161.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +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> 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 q; + std::vector 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; +} diff --git a/S2OJ/161/data/graph1.ans b/S2OJ/161/data/graph1.ans new file mode 100644 index 00000000..9568403d --- /dev/null +++ b/S2OJ/161/data/graph1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61ff27e05eefe7b3f0a99d2a114c5ede7a415e6abb9aee377c0db6ca4726e916 +size 8 diff --git a/S2OJ/161/data/graph1.in b/S2OJ/161/data/graph1.in new file mode 100644 index 00000000..7a3860b9 --- /dev/null +++ b/S2OJ/161/data/graph1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b9f4b2685a250209b8b08a28d4d2d9772861f437b6973ba97f44e06fdaf35e0 +size 121 diff --git a/S2OJ/161/data/graph10.ans b/S2OJ/161/data/graph10.ans new file mode 100644 index 00000000..d5b27fdf --- /dev/null +++ b/S2OJ/161/data/graph10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc95b46617b8f4ce9e18b4d363233134fa359bdf54a32d1252719d965cd8bdf0 +size 8 diff --git a/S2OJ/161/data/graph10.in b/S2OJ/161/data/graph10.in new file mode 100644 index 00000000..8636954e --- /dev/null +++ b/S2OJ/161/data/graph10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b88d2b34b8e9de63b101ce1353322ae9b3be0b5c3226c9871d2accf54a6a13ff +size 6378 diff --git a/S2OJ/161/data/graph2.ans b/S2OJ/161/data/graph2.ans new file mode 100644 index 00000000..b5944736 --- /dev/null +++ b/S2OJ/161/data/graph2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48458e49ecb6a183166ff260a12f5a6fea32e8dc1a11bd8dba291f87d2dbcb56 +size 7 diff --git a/S2OJ/161/data/graph2.in b/S2OJ/161/data/graph2.in new file mode 100644 index 00000000..71c63f0c --- /dev/null +++ b/S2OJ/161/data/graph2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54bae811d7aa94fb4aa096a4c8747b5c4266c0fda0b4644d936bfae9d3f3085b +size 580 diff --git a/S2OJ/161/data/graph3.ans b/S2OJ/161/data/graph3.ans new file mode 100644 index 00000000..2bb7f7a3 --- /dev/null +++ b/S2OJ/161/data/graph3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:738d85f855f03bd86046fc592877b07ad99d36d0c7f36e63a4a4926c96cb19ea +size 8 diff --git a/S2OJ/161/data/graph3.in b/S2OJ/161/data/graph3.in new file mode 100644 index 00000000..7894f2d7 --- /dev/null +++ b/S2OJ/161/data/graph3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc0360a6380360bac0bb47d532f6a5426bc6dd57b3061fece7b655c7b8d0329d +size 613 diff --git a/S2OJ/161/data/graph4.ans b/S2OJ/161/data/graph4.ans new file mode 100644 index 00000000..93ffa8af --- /dev/null +++ b/S2OJ/161/data/graph4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:270d64e15d7ed4987185aaf70c842e15ee256d1b350398ec5107ee5665367a21 +size 8 diff --git a/S2OJ/161/data/graph4.in b/S2OJ/161/data/graph4.in new file mode 100644 index 00000000..627539c9 --- /dev/null +++ b/S2OJ/161/data/graph4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4526d7885dad5fd11172377005042d3b455076312ac0d51088cf051507e1d798 +size 621 diff --git a/S2OJ/161/data/graph5.ans b/S2OJ/161/data/graph5.ans new file mode 100644 index 00000000..aed9909c --- /dev/null +++ b/S2OJ/161/data/graph5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92c22a748f1e6f8f4d401a7f1375265eb3bf0ce6322cdf865e176b61402c1003 +size 8 diff --git a/S2OJ/161/data/graph5.in b/S2OJ/161/data/graph5.in new file mode 100644 index 00000000..bc5b53f2 --- /dev/null +++ b/S2OJ/161/data/graph5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3cc2e7b9d6786d4d2941e60739003996d44f2183062c6e18271483ac0a7fd33 +size 2524 diff --git a/S2OJ/161/data/graph6.ans b/S2OJ/161/data/graph6.ans new file mode 100644 index 00000000..40e34eba --- /dev/null +++ b/S2OJ/161/data/graph6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc09e6b0142fd5f048788b478fdb71b7054a8c8a7ec31cf9b89b5e569c162f31 +size 8 diff --git a/S2OJ/161/data/graph6.in b/S2OJ/161/data/graph6.in new file mode 100644 index 00000000..4b21dc22 --- /dev/null +++ b/S2OJ/161/data/graph6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:788bc2346a17db92a36e6479085e1d39759b305fbb59fa21cf3c106ad967022c +size 1269 diff --git a/S2OJ/161/data/graph7.ans b/S2OJ/161/data/graph7.ans new file mode 100644 index 00000000..dca4281f --- /dev/null +++ b/S2OJ/161/data/graph7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:889f0728c9974274b3472a71b2d0338fc4ac9b98d4d9861556dd4fa4cbf3993a +size 8 diff --git a/S2OJ/161/data/graph7.in b/S2OJ/161/data/graph7.in new file mode 100644 index 00000000..645801c2 --- /dev/null +++ b/S2OJ/161/data/graph7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31a4ffb841e69832b6785fc659b97e2fe5e2c043418d52542eac5e745881d738 +size 2551 diff --git a/S2OJ/161/data/graph8.ans b/S2OJ/161/data/graph8.ans new file mode 100644 index 00000000..f2f64c47 --- /dev/null +++ b/S2OJ/161/data/graph8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8efb9a76dfa1b22010928fd29eadbdfca85de71422e7ffd77fa1b15556a86bf +size 8 diff --git a/S2OJ/161/data/graph8.in b/S2OJ/161/data/graph8.in new file mode 100644 index 00000000..bbf7318e --- /dev/null +++ b/S2OJ/161/data/graph8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d3866e0ef15c597ccc8a160bab115c33388ecfa5ed7c7378aff3bd05b175e8e +size 3838 diff --git a/S2OJ/161/data/graph9.ans b/S2OJ/161/data/graph9.ans new file mode 100644 index 00000000..79597559 --- /dev/null +++ b/S2OJ/161/data/graph9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01890ca65c758770eda8a40713ef41c0128301f9c9f4209ecd251279db91f272 +size 8 diff --git a/S2OJ/161/data/graph9.in b/S2OJ/161/data/graph9.in new file mode 100644 index 00000000..ac777070 --- /dev/null +++ b/S2OJ/161/data/graph9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06b65b42686e7933b44a9fa5d8c86c2e165df29d995f3fddf0e307e378cb3977 +size 6381 diff --git a/S2OJ/161/data/problem.conf b/S2OJ/161/data/problem.conf new file mode 100644 index 00000000..73a888d6 --- /dev/null +++ b/S2OJ/161/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0864e1973855ac4ff5db8b06ebb9500370ac0055c9898eb325dc27138aeac0b +size 237 diff --git a/S2OJ/161/data/std.cpp b/S2OJ/161/data/std.cpp new file mode 100644 index 00000000..28c68eb2 --- /dev/null +++ b/S2OJ/161/data/std.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ecf9f098fa1fd76d468d179da0ced97171d1fd7a3bf24f75b25facfce79123a +size 1156 diff --git a/S2OJ/161/data/val.cpp b/S2OJ/161/data/val.cpp new file mode 100644 index 00000000..ad867222 --- /dev/null +++ b/S2OJ/161/data/val.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1e9cba5f935b8d21352fc5d187245d5f38015e66d804f3c9067f0a58b907031 +size 891