diff --git a/S2OJ/1912/1912.cpp b/S2OJ/1912/1912.cpp new file mode 100644 index 00000000..046e2c20 --- /dev/null +++ b/S2OJ/1912/1912.cpp @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 305, + M = 3e4 + 5; +const int INF = 0x3f3f3f3f; + +int n, m, k, x[M], y[M], z[M]; +double p[N][N], f[N][N]; +std::vector> g[N]; +int dist[N]; +bool vis[N]; + +void dijkstra(int s) { + std::fill(std::begin(dist), std::end(dist), INF); + std::fill(std::begin(vis), std::end(vis), false); + + std::priority_queue, std::vector>, std::greater<>> q; + + q.emplace(0, s); + dist[s] = 0; + + while (!q.empty()) { + int u = q.top().second; + q.pop(); + + if (vis[u]) continue; + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (dist[v] > dist[u] + w) { + dist[v] = dist[u] + w; + + q.emplace(dist[v], v); + } + } + + vis[u] = true; + } +} + +void dfs(int u) { + if (g[u].empty()) { + std::copy(std::begin(p[u]), std::end(p[u]), std::begin(f[u])); + + return; + } + + for (auto e : g[u]) { + int v = e.first; + + dfs(v); + + for (int i = k; i; i--) { + for (int j = 1; j <= i; j++) { + f[u][i] = std::max(f[u][i], f[u][i - j] + f[v][j] / g[u].size()); + } + } + } + + for (int i = k; i; i--) { + for (int j = 1; j <= i; j++) { + f[u][i] = std::max(f[u][i], p[u][j] + f[u][i - j] * (1.0 - p[u][j])); + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> k; + + for (int i = 1; i <= m; i++) { + cin >> x[i] >> y[i] >> z[i]; + + g[x[i]].emplace_back(y[i], z[i]); + g[y[i]].emplace_back(x[i], z[i]); + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= k; j++) { + cin >> p[i][j]; + } + } + + dijkstra(1); + std::fill(std::begin(g), std::end(g), std::vector>()); + + for (int i = 1; i <= m; i++) { + if (dist[x[i]] + z[i] == dist[y[i]]) { + g[x[i]].emplace_back(y[i], 0); + } + + if (dist[y[i]] + z[i] == dist[x[i]]) { + g[y[i]].emplace_back(x[i], 0); + } + } + + dfs(1); + + cout << std::fixed << std::setprecision(6) << f[1][k] << endl; + + return 0; +} diff --git a/S2OJ/1912/data/arrest1.in b/S2OJ/1912/data/arrest1.in new file mode 100644 index 00000000..6490e4f7 --- /dev/null +++ b/S2OJ/1912/data/arrest1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dea56fb70f7b893db26a0442887d5e71581e5f5b90842b845f19b862ddd6175 +size 341 diff --git a/S2OJ/1912/data/arrest1.out b/S2OJ/1912/data/arrest1.out new file mode 100644 index 00000000..b6700008 --- /dev/null +++ b/S2OJ/1912/data/arrest1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff169ed858b3571b7610a5307283cc151fa45bd60d018e7697c328f962c89cac +size 9 diff --git a/S2OJ/1912/data/arrest10.in b/S2OJ/1912/data/arrest10.in new file mode 100644 index 00000000..274f9e95 --- /dev/null +++ b/S2OJ/1912/data/arrest10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a19138048ce347d0b73e01d71432d585e89d18e81aeb7af88d418e27638e4fb4 +size 1237428 diff --git a/S2OJ/1912/data/arrest10.out b/S2OJ/1912/data/arrest10.out new file mode 100644 index 00000000..a35ad3ec --- /dev/null +++ b/S2OJ/1912/data/arrest10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7164944a76adf154d4a00a5ce05d7d7e75c75a9eddf6a105df5c764f3d1146c9 +size 9 diff --git a/S2OJ/1912/data/arrest2.in b/S2OJ/1912/data/arrest2.in new file mode 100644 index 00000000..6fb279fd --- /dev/null +++ b/S2OJ/1912/data/arrest2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81884700ca593b00ee776b2add181595835855c97985a67321c79b91728c7d1a +size 383 diff --git a/S2OJ/1912/data/arrest2.out b/S2OJ/1912/data/arrest2.out new file mode 100644 index 00000000..2752c8c0 --- /dev/null +++ b/S2OJ/1912/data/arrest2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1db4e1dda243cbec9f4e0a7147249200652f8a8bb97582d29484b445b746e017 +size 9 diff --git a/S2OJ/1912/data/arrest3.in b/S2OJ/1912/data/arrest3.in new file mode 100644 index 00000000..8ff3db04 --- /dev/null +++ b/S2OJ/1912/data/arrest3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:715744672920fc611b512896f151fc8ed21388dd5e4ac87750d4e6dd5b634e61 +size 18726 diff --git a/S2OJ/1912/data/arrest3.out b/S2OJ/1912/data/arrest3.out new file mode 100644 index 00000000..b0f82107 --- /dev/null +++ b/S2OJ/1912/data/arrest3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70dda28492b5ae0bc5dc7c01e61c8b2774957e9ded88b38ee0ca1e3328ea2753 +size 9 diff --git a/S2OJ/1912/data/arrest4.in b/S2OJ/1912/data/arrest4.in new file mode 100644 index 00000000..9a34d1f4 --- /dev/null +++ b/S2OJ/1912/data/arrest4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0bbeff845ceed78176d6770056b67f25fd7b34155df239e9eb4969eb532f041a +size 11883 diff --git a/S2OJ/1912/data/arrest4.out b/S2OJ/1912/data/arrest4.out new file mode 100644 index 00000000..765fcab5 --- /dev/null +++ b/S2OJ/1912/data/arrest4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10063e3734283bb64943c535b515ada67f5fd88cce4780397850609feef8222f +size 9 diff --git a/S2OJ/1912/data/arrest5.in b/S2OJ/1912/data/arrest5.in new file mode 100644 index 00000000..c8190014 --- /dev/null +++ b/S2OJ/1912/data/arrest5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a11e0cf87051e9cd1fb8d1c2177e50b6b1baf061f2d4ea78b76a936b3e4d83e1 +size 23135 diff --git a/S2OJ/1912/data/arrest5.out b/S2OJ/1912/data/arrest5.out new file mode 100644 index 00000000..7ff2fd91 --- /dev/null +++ b/S2OJ/1912/data/arrest5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66cc0af936badc48e81cf21d243e3f74c26fe17b3a842e8ebc17cd8721004ebf +size 9 diff --git a/S2OJ/1912/data/arrest6.in b/S2OJ/1912/data/arrest6.in new file mode 100644 index 00000000..65c8864e --- /dev/null +++ b/S2OJ/1912/data/arrest6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:815ef1e0df803cb0a4cdfac4416725f7132739a14e39ccd75e4131a912257a95 +size 1059267 diff --git a/S2OJ/1912/data/arrest6.out b/S2OJ/1912/data/arrest6.out new file mode 100644 index 00000000..61bbb61f --- /dev/null +++ b/S2OJ/1912/data/arrest6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8c7b866f0f0270adcb70bfe3e696df7f211e811d86eec018429d085495e3454 +size 9 diff --git a/S2OJ/1912/data/arrest7.in b/S2OJ/1912/data/arrest7.in new file mode 100644 index 00000000..85577a08 --- /dev/null +++ b/S2OJ/1912/data/arrest7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8414d734c3a8d52275b61c24e98ca345fb26e031782fb43bb5bba0265b9b424 +size 1177686 diff --git a/S2OJ/1912/data/arrest7.out b/S2OJ/1912/data/arrest7.out new file mode 100644 index 00000000..c750c08b --- /dev/null +++ b/S2OJ/1912/data/arrest7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d64d2135f5852a0ebd2813116efa13c6668ef08f5c625dd3f5027aac8ab64f5 +size 9 diff --git a/S2OJ/1912/data/arrest8.in b/S2OJ/1912/data/arrest8.in new file mode 100644 index 00000000..723d1c04 --- /dev/null +++ b/S2OJ/1912/data/arrest8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6432991dc5b1cbdd0a552a32501dbb39ec0060fea0ae91bfd9a30b5dd3668c1 +size 1237207 diff --git a/S2OJ/1912/data/arrest8.out b/S2OJ/1912/data/arrest8.out new file mode 100644 index 00000000..b854145f --- /dev/null +++ b/S2OJ/1912/data/arrest8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec1e89d5799062232205765458e9135366a61cef192497fadca33bc3e1a91259 +size 9 diff --git a/S2OJ/1912/data/arrest9.in b/S2OJ/1912/data/arrest9.in new file mode 100644 index 00000000..7044b244 --- /dev/null +++ b/S2OJ/1912/data/arrest9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6763b6f9bda1a9f8e322c6757464fb4bb664a1b38d963edaa8cd3f6501a4866a +size 970142 diff --git a/S2OJ/1912/data/arrest9.out b/S2OJ/1912/data/arrest9.out new file mode 100644 index 00000000..b615ee86 --- /dev/null +++ b/S2OJ/1912/data/arrest9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b90f7043f4536464b0fa17b31b31d1c843e993dcd17bf976bb1c7bcf6e9deda2 +size 9 diff --git a/S2OJ/1912/data/ex_arrest1.in b/S2OJ/1912/data/ex_arrest1.in new file mode 100644 index 00000000..96b5ed53 --- /dev/null +++ b/S2OJ/1912/data/ex_arrest1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85095ea7927a3455792713d7cbe68c9ae372d81fc0f4ca3e7aaab1438c084576 +size 63 diff --git a/S2OJ/1912/data/ex_arrest1.out b/S2OJ/1912/data/ex_arrest1.out new file mode 100644 index 00000000..763224d1 --- /dev/null +++ b/S2OJ/1912/data/ex_arrest1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a7a3a0ba70c0106794450d5c3c7c17adc6fddcefa26de1c341dc33b09c3c9b2 +size 9 diff --git a/S2OJ/1912/data/ex_arrest2.in b/S2OJ/1912/data/ex_arrest2.in new file mode 100644 index 00000000..82aab7a6 --- /dev/null +++ b/S2OJ/1912/data/ex_arrest2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ea26274b003959d3b555349a1cf9c830dedddf0b3082771cedf9346204af7ce +size 814084 diff --git a/S2OJ/1912/data/ex_arrest2.out b/S2OJ/1912/data/ex_arrest2.out new file mode 100644 index 00000000..0f49eb11 --- /dev/null +++ b/S2OJ/1912/data/ex_arrest2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50d3a69b930457282debea3d352ae49803a15f0843ae1699399ef4de2f4f7cdd +size 9 diff --git a/S2OJ/1912/data/problem.conf b/S2OJ/1912/data/problem.conf new file mode 100644 index 00000000..cc2a8da8 --- /dev/null +++ b/S2OJ/1912/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f72f713674442a4abb9a78c93242a36ac789d2c677e56194eff47fbb684e0685 +size 301