diff --git a/BZOJ/3242/3242.cpp b/BZOJ/3242/3242.cpp new file mode 100644 index 00000000..4454a260 --- /dev/null +++ b/BZOJ/3242/3242.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; +const long long INF = 0x3f3f3f3f'3f3f3f3f; + +int n; +long long dist[N], dep[N], pre[N], suf[N], a[N], b[N], c[N], d[N], ans1, ans2; +std::vector> g[N], circle; +bool vis[N], on_circle[N]; + +bool dfs(int u, int f) { + if (vis[u]) return true; + + vis[u] = true; + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (v == f) continue; + + if (dfs(v, u)) { + circle.emplace_back(v, w); + on_circle[v] = true; + + return true; + } + } + + return false; +} + +std::pair bfs(int s) { + int res = s; + std::queue q; + std::unordered_set set; + + q.emplace(s); + set.emplace(s); + dist[s] = 0; + vis[s] = true; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (!vis[v] && !on_circle[v]) { + dist[v] = dist[u] + w; + + if (dist[v] > dist[res]) res = v; + + q.emplace(v); + set.emplace(v); + vis[v] = true; + } + } + } + + long long dist_res = dist[res]; + + for (int u : set) { + vis[u] = false; + dist[u] = INF; + } + + return {res, dist_res}; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1, u, v, w; i <= n; i++) { + cin >> u >> v >> w; + + g[u].emplace_back(v, w); + g[v].emplace_back(u, w); + } + + dfs(1, 0); + std::reverse(circle.begin(), circle.end()); + std::fill(std::begin(vis), std::end(vis), false); + std::fill(std::begin(dist), std::end(dist), INF); + + for (int i = 1; i <= circle.size(); i++) { + int u = circle[i - 1].first; + + on_circle[u] = false; + + auto o = bfs(u); + + dep[i] = o.second; + ans1 = std::max(ans1, bfs(o.first).second); + + on_circle[u] = true; + } + + for (int i = 2; i <= circle.size(); i++) { + pre[i] = pre[i - 1] + circle[i - 1].second; + } + + for (int i = circle.size() - 1; i; i--) { + suf[i] = suf[i + 1] + circle[i].second; + } + + for (int i = 1; i <= circle.size(); i++) { + a[i] = std::max(a[i - 1], dep[i] + pre[i]); + } + + for (int i = circle.size(); i; i--) { + b[i] = std::max(b[i + 1], dep[i] + suf[i]); + } + + long long max = 0; + for (int i = 1; i <= circle.size(); i++) { + c[i] = std::max(c[i - 1], max + dep[i] + pre[i]); + max = std::max(max, dep[i] - pre[i]); + } + + max = 0; + for (int i = circle.size(); i; i--) { + d[i] = std::max(d[i + 1], max + dep[i] + suf[i]); + max = std::max(max, dep[i] - suf[i]); + } + + ans2 = INF; + for (int i = 1; i < circle.size(); i++) { + ans2 = std::min(ans2, std::max({a[i] + b[i + 1] + circle[0].second, c[i], d[i + 1]})); + } + + cout << std::fixed << std::setprecision(1) << static_cast(std::max(ans1, ans2)) / 2 << endl; + + return 0; +} diff --git a/BZOJ/3242/data/1.in b/BZOJ/3242/data/1.in new file mode 100644 index 00000000..79178a85 --- /dev/null +++ b/BZOJ/3242/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8cc2166ce60a8edf3d07db411e7b806f3270caa7ab73af805875afd0ff5795e7 +size 6330 diff --git a/BZOJ/3242/data/1.out b/BZOJ/3242/data/1.out new file mode 100644 index 00000000..206ecd92 --- /dev/null +++ b/BZOJ/3242/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51d1c2fb09d3cce237949430d025cbcec36593161edb9764757714f12e831bdd +size 8 diff --git a/BZOJ/3242/data/10.in b/BZOJ/3242/data/10.in new file mode 100644 index 00000000..3cd82720 --- /dev/null +++ b/BZOJ/3242/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:017314d542a3416977510dc60a75769ecd6d125db41a6fa8d85b2f669020aa00 +size 36548 diff --git a/BZOJ/3242/data/10.out b/BZOJ/3242/data/10.out new file mode 100644 index 00000000..10b98d6b --- /dev/null +++ b/BZOJ/3242/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cea1ab62f47991611e73a09cbc883f7881c3b1b1c2a342a7916c9f6045e0218e +size 13 diff --git a/BZOJ/3242/data/11.in b/BZOJ/3242/data/11.in new file mode 100644 index 00000000..91e81c19 --- /dev/null +++ b/BZOJ/3242/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10a16f794e2ec0609c0e7c9372222e39b8bf6b5b5a5ee1f22cdad6589e8a8071 +size 17609 diff --git a/BZOJ/3242/data/11.out b/BZOJ/3242/data/11.out new file mode 100644 index 00000000..637907de --- /dev/null +++ b/BZOJ/3242/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d79c3c40f7c86c9da96195d35bc6eb684203f411d4c5df082fc6d0a063f055e +size 14 diff --git a/BZOJ/3242/data/12.in b/BZOJ/3242/data/12.in new file mode 100644 index 00000000..de0a472c --- /dev/null +++ b/BZOJ/3242/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8bf650adb2050cfbced72801b1295f6b91f18f957a8c12214b2916510dc698 +size 37433 diff --git a/BZOJ/3242/data/12.out b/BZOJ/3242/data/12.out new file mode 100644 index 00000000..6b41a50b --- /dev/null +++ b/BZOJ/3242/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d7626fb87d069c08aaeed1e7bb5f5ad1c9894e07311084e0b9b62a0388e6880 +size 15 diff --git a/BZOJ/3242/data/13.in b/BZOJ/3242/data/13.in new file mode 100644 index 00000000..85d65446 --- /dev/null +++ b/BZOJ/3242/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ad56a8a02f45644c6fb9ef6d5ef90039b57ae162ca2175adbe48425371eeba1 +size 33436 diff --git a/BZOJ/3242/data/13.out b/BZOJ/3242/data/13.out new file mode 100644 index 00000000..c9fe387d --- /dev/null +++ b/BZOJ/3242/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea5ee49940f90667a85853ebe7370330d72385107078640fe634b2d568e5a5e4 +size 14 diff --git a/BZOJ/3242/data/14.in b/BZOJ/3242/data/14.in new file mode 100644 index 00000000..cc6d6045 --- /dev/null +++ b/BZOJ/3242/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2be499d679a684701e75cc9078e7265355015e46a51aa870a80e7782539f84c9 +size 623 diff --git a/BZOJ/3242/data/14.out b/BZOJ/3242/data/14.out new file mode 100644 index 00000000..03027455 --- /dev/null +++ b/BZOJ/3242/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c5926591febc2c633b373704a1ec076694f581caf687a6798068ad78891a925 +size 5 diff --git a/BZOJ/3242/data/15.in b/BZOJ/3242/data/15.in new file mode 100644 index 00000000..45df8564 --- /dev/null +++ b/BZOJ/3242/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8850c4276557c1ec0637f0f9b75461430f8752b814979b5ee8c648fc1c512c2 +size 1723875 diff --git a/BZOJ/3242/data/15.out b/BZOJ/3242/data/15.out new file mode 100644 index 00000000..2d34d790 --- /dev/null +++ b/BZOJ/3242/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e25c2d0babe8e36eed3adf76b965dd088f79691989c53751abff3e576dcd15ed +size 15 diff --git a/BZOJ/3242/data/16.in b/BZOJ/3242/data/16.in new file mode 100644 index 00000000..fa29b811 --- /dev/null +++ b/BZOJ/3242/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc52bb16ac0cd146f00fbf5c0ca368bf20dda1686e1246faa4cf49e7e1e0933a +size 850408 diff --git a/BZOJ/3242/data/16.out b/BZOJ/3242/data/16.out new file mode 100644 index 00000000..9c215536 --- /dev/null +++ b/BZOJ/3242/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0694f6c5b24889fa3450d5b1c4ee587730ba0e7afaf45b6f7e4ac4c31426e92 +size 16 diff --git a/BZOJ/3242/data/17.in b/BZOJ/3242/data/17.in new file mode 100644 index 00000000..9f5a810e --- /dev/null +++ b/BZOJ/3242/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cc802197e93c5e378ce37d3b1e7938a42216e45bea8d7ae0935f3dfd6b8685e +size 65 diff --git a/BZOJ/3242/data/17.out b/BZOJ/3242/data/17.out new file mode 100644 index 00000000..8c54c7cb --- /dev/null +++ b/BZOJ/3242/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5c0dfc64d745c1bff4a4f6397214178e1597fc224cdb21bb7783e556ed8493f +size 4 diff --git a/BZOJ/3242/data/18.in b/BZOJ/3242/data/18.in new file mode 100644 index 00000000..cbdc035a --- /dev/null +++ b/BZOJ/3242/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e33f0f8a78fe174b963e09d18b70a4f6a5b4c2f4435d04ff386e315b31d514ac +size 2157554 diff --git a/BZOJ/3242/data/18.out b/BZOJ/3242/data/18.out new file mode 100644 index 00000000..421ebae4 --- /dev/null +++ b/BZOJ/3242/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:376246a3fdbf6e14de9520d805a693df9b2bb436338e94b550da2d54b9bd41ca +size 15 diff --git a/BZOJ/3242/data/19.in b/BZOJ/3242/data/19.in new file mode 100644 index 00000000..f89f08cf --- /dev/null +++ b/BZOJ/3242/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:980eb415f80f9336594312116bb839655e00d7379c046420ba2e673f0c51ce12 +size 30272 diff --git a/BZOJ/3242/data/19.out b/BZOJ/3242/data/19.out new file mode 100644 index 00000000..e3e2afe3 --- /dev/null +++ b/BZOJ/3242/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7567a6e635c318538732f973459ea93fa09e69c89ad63ea2975c150a028280f +size 13 diff --git a/BZOJ/3242/data/2.in b/BZOJ/3242/data/2.in new file mode 100644 index 00000000..a913e826 --- /dev/null +++ b/BZOJ/3242/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:500385bd5f84c28eef5b33fba6bfcc8f55b0045d41f69e275cdb885faf12ce79 +size 1721556 diff --git a/BZOJ/3242/data/2.out b/BZOJ/3242/data/2.out new file mode 100644 index 00000000..5fa0eb46 --- /dev/null +++ b/BZOJ/3242/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d70b7e204b64980fc765beccc11e23fa0346f8aa89e48a176bb54bc26937c52 +size 15 diff --git a/BZOJ/3242/data/20.in b/BZOJ/3242/data/20.in new file mode 100644 index 00000000..bda0b7ca --- /dev/null +++ b/BZOJ/3242/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0282c1d4839307d008d32e35fe3815eee91aa585ac63c7ecabb43fd617d870d +size 2159668 diff --git a/BZOJ/3242/data/20.out b/BZOJ/3242/data/20.out new file mode 100644 index 00000000..27f36a1a --- /dev/null +++ b/BZOJ/3242/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c400d5d73f4cd04ad35c683a3122065388c600cd69c344b1eac43561ea098ad +size 17 diff --git a/BZOJ/3242/data/3.in b/BZOJ/3242/data/3.in new file mode 100644 index 00000000..2264aaf1 --- /dev/null +++ b/BZOJ/3242/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb587ef99793842584f37221302a2a4be0b53d01cafc79096d6a755707fa220b +size 2159356 diff --git a/BZOJ/3242/data/3.out b/BZOJ/3242/data/3.out new file mode 100644 index 00000000..f2892c1e --- /dev/null +++ b/BZOJ/3242/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f71f303723098fffc25e6b94980597a94eff15522c412760830cd0cbc8d5528e +size 17 diff --git a/BZOJ/3242/data/4.in b/BZOJ/3242/data/4.in new file mode 100644 index 00000000..c13b77da --- /dev/null +++ b/BZOJ/3242/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd504d5ec407c009fe1d8183213debad352d748f6268ae85c9eb721e8458eea3 +size 4152 diff --git a/BZOJ/3242/data/4.out b/BZOJ/3242/data/4.out new file mode 100644 index 00000000..063bb042 --- /dev/null +++ b/BZOJ/3242/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b26c764f447be003e64ba7ec00ac225c40086db0b51905a4d0c9cc2e9ac3952 +size 7 diff --git a/BZOJ/3242/data/5.in b/BZOJ/3242/data/5.in new file mode 100644 index 00000000..8233b089 --- /dev/null +++ b/BZOJ/3242/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7eede39c495a955f35e6ef356b7bef77bf7bb6a7ef011cf1956817b548fa9559 +size 3064 diff --git a/BZOJ/3242/data/5.out b/BZOJ/3242/data/5.out new file mode 100644 index 00000000..eb4a54eb --- /dev/null +++ b/BZOJ/3242/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ebe9724f11536171f33d9da495fd0905bb02147c1a3735fb6169b08858c150a +size 7 diff --git a/BZOJ/3242/data/6.in b/BZOJ/3242/data/6.in new file mode 100644 index 00000000..c498c750 --- /dev/null +++ b/BZOJ/3242/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce3230b97f10115c0af5aef3ad01f2fd54f63e8d5ab57df9a1a84fcd1b2ab2de +size 1504887 diff --git a/BZOJ/3242/data/6.out b/BZOJ/3242/data/6.out new file mode 100644 index 00000000..8bce6ce2 --- /dev/null +++ b/BZOJ/3242/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f54dad815f4dff98682f546006e0f6346656d948fae8fe5c71bff2923deaa45 +size 16 diff --git a/BZOJ/3242/data/7.in b/BZOJ/3242/data/7.in new file mode 100644 index 00000000..b5ad06fc --- /dev/null +++ b/BZOJ/3242/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81e32366275fbab1078ab4037a3e8c30c9c695cb44d51a5dd3f45bb81857c7fb +size 6338 diff --git a/BZOJ/3242/data/7.out b/BZOJ/3242/data/7.out new file mode 100644 index 00000000..4c7ecc20 --- /dev/null +++ b/BZOJ/3242/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cd32df64c7a7107a3de41059bd3afbd6dddc9706c7f4849f7bfbdd393a6943b +size 7 diff --git a/BZOJ/3242/data/8.in b/BZOJ/3242/data/8.in new file mode 100644 index 00000000..12a34523 --- /dev/null +++ b/BZOJ/3242/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d45f5113c2f52de458cb33ad88b734e5c0a3043581c27f1213934a1269ed6c59 +size 27521 diff --git a/BZOJ/3242/data/8.out b/BZOJ/3242/data/8.out new file mode 100644 index 00000000..3174715b --- /dev/null +++ b/BZOJ/3242/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be096f6e95090a9e69df5f51281e2c68da6a67a0c6bf0fcde89307c34050ab00 +size 15 diff --git a/BZOJ/3242/data/9.in b/BZOJ/3242/data/9.in new file mode 100644 index 00000000..f961c29a --- /dev/null +++ b/BZOJ/3242/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4068f7c831a260086273a0cbd0cdfa3a2076c1f0df0f2779e769c1410a0eb2b +size 412127 diff --git a/BZOJ/3242/data/9.out b/BZOJ/3242/data/9.out new file mode 100644 index 00000000..3545c43f --- /dev/null +++ b/BZOJ/3242/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60036b9a6a9be0ad9c0e2f3367cff4791714452ccb2492f8094e78a8f1dcf3a3 +size 14