0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 16:05:25 +00:00

#1788. 【2017.3长乐省选集训Day8T3】修路

https://sjzezoj.com/submission/65457
This commit is contained in:
Baoshuo Ren 2022-12-05 20:15:31 +08:00
parent 47dc0cc260
commit e03f98b65e
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 168 additions and 0 deletions

105
S2OJ/1788/1788.cpp Normal file
View File

@ -0,0 +1,105 @@
#include <iostream>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e4 + 5,
K = 11;
const int INF = 0x3f3f3f3f;
int n, m, d, f[1 << K][N], f1[1 << K];
std::vector<std::pair<int, int>> g[N];
int steiner(int s) {
int k = 0;
memset(f, 0x3f, sizeof(f));
for (int i = 1; i <= d; i++) {
std::queue<int> q;
if (s & (1 << (i - 1))) {
f[1 << k++][i] = 0;
f[1 << k++][n - i + 1] = 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;
}
}
}
}
}
int res = INF;
for (int i = 1; i <= n; i++) {
res = std::min(res, f[(1 << k) - 1][i]);
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> d;
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(f1, 0x3f, sizeof(f1));
f1[0] = 0;
for (int s = 1; s < 1 << d; s++) {
for (int t = s; t; t = (t - 1) & s) {
f1[s] = std::min(f1[s], f1[s ^ t] + steiner(t));
}
}
cout << (f1[(1 << d) - 1] == INF ? -1 : f1[(1 << d) - 1]) << endl;
return 0;
}

BIN
S2OJ/1788/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1788/data/road9.out (Stored with Git LFS) Normal file

Binary file not shown.