diff --git a/LibreOJ/2669/2669.cpp b/LibreOJ/2669/2669.cpp new file mode 100644 index 00000000..4454a260 --- /dev/null +++ b/LibreOJ/2669/2669.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/LibreOJ/2669/data/foodshop1.ans b/LibreOJ/2669/data/foodshop1.ans new file mode 100644 index 00000000..3602cf7e --- /dev/null +++ b/LibreOJ/2669/data/foodshop1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:214a41a4198de01a387c92bff37cc880f23de587f53ac0c9f688d56a77e43d74 +size 5 diff --git a/LibreOJ/2669/data/foodshop1.in b/LibreOJ/2669/data/foodshop1.in new file mode 100644 index 00000000..7e10521c --- /dev/null +++ b/LibreOJ/2669/data/foodshop1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f81c5b35a9353793e8852c7863fd7a92c6d078cf46bded5f777179c61fa4f6f0 +size 76 diff --git a/LibreOJ/2669/data/foodshop10.ans b/LibreOJ/2669/data/foodshop10.ans new file mode 100644 index 00000000..a19ee778 --- /dev/null +++ b/LibreOJ/2669/data/foodshop10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86ad7f78b16378076726ae878aba94cab73e57ec38b00eb67005e5b1b8631941 +size 15 diff --git a/LibreOJ/2669/data/foodshop10.in b/LibreOJ/2669/data/foodshop10.in new file mode 100644 index 00000000..ad0de7b0 --- /dev/null +++ b/LibreOJ/2669/data/foodshop10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c2baa7b18bc801388c01fc4354d3b061a50a9ab7f655b11754db56e1f227f5a +size 35237 diff --git a/LibreOJ/2669/data/foodshop11.ans b/LibreOJ/2669/data/foodshop11.ans new file mode 100644 index 00000000..b6120fe5 --- /dev/null +++ b/LibreOJ/2669/data/foodshop11.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b74236807a9a207337660eb5de0453848cab9c7ca8756fdaff0c19fcdb69e51 +size 16 diff --git a/LibreOJ/2669/data/foodshop11.in b/LibreOJ/2669/data/foodshop11.in new file mode 100644 index 00000000..f4b830e0 --- /dev/null +++ b/LibreOJ/2669/data/foodshop11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92a14724ceb3a5b765b22001b4ba7cc70ec8428a3bc549af5e5daf112080dc33 +size 39434 diff --git a/LibreOJ/2669/data/foodshop12.ans b/LibreOJ/2669/data/foodshop12.ans new file mode 100644 index 00000000..8ca1135f --- /dev/null +++ b/LibreOJ/2669/data/foodshop12.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85b5800ba90d36957cb9e02e2fa6f5408d12b1561508377937145254823c1a72 +size 14 diff --git a/LibreOJ/2669/data/foodshop12.in b/LibreOJ/2669/data/foodshop12.in new file mode 100644 index 00000000..98673618 --- /dev/null +++ b/LibreOJ/2669/data/foodshop12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86a6f2d4ff516e5b9e501ce29c72a00be0e472cb662733c68d65b1c852b45da5 +size 38549 diff --git a/LibreOJ/2669/data/foodshop13.ans b/LibreOJ/2669/data/foodshop13.ans new file mode 100644 index 00000000..59f7a523 --- /dev/null +++ b/LibreOJ/2669/data/foodshop13.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf95453921655e8e520ba563d35f1c45a24f066afd2bcf5e116489d5aeef7271 +size 15 diff --git a/LibreOJ/2669/data/foodshop13.in b/LibreOJ/2669/data/foodshop13.in new file mode 100644 index 00000000..55987f36 --- /dev/null +++ b/LibreOJ/2669/data/foodshop13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44cab7dcbe09af2cc21e010344dd8392621eadaf758e70101dc384d843186176 +size 432128 diff --git a/LibreOJ/2669/data/foodshop14.ans b/LibreOJ/2669/data/foodshop14.ans new file mode 100644 index 00000000..47784ca3 --- /dev/null +++ b/LibreOJ/2669/data/foodshop14.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55fefc22ee425cd0e78f2918dfafabbfdc5cd86d883f665525f0c8098e2019cc +size 17 diff --git a/LibreOJ/2669/data/foodshop14.in b/LibreOJ/2669/data/foodshop14.in new file mode 100644 index 00000000..ba075b7e --- /dev/null +++ b/LibreOJ/2669/data/foodshop14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c91e756a76343986e679e1335b50d64a5d9ef53a9be9a4375a28cff392e57e9 +size 890409 diff --git a/LibreOJ/2669/data/foodshop15.ans b/LibreOJ/2669/data/foodshop15.ans new file mode 100644 index 00000000..61c72fec --- /dev/null +++ b/LibreOJ/2669/data/foodshop15.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:baace6f91337b789587044d29d7a47a8234920f2ba4470fdb204bead8e81522c +size 17 diff --git a/LibreOJ/2669/data/foodshop15.in b/LibreOJ/2669/data/foodshop15.in new file mode 100644 index 00000000..2f6501c6 --- /dev/null +++ b/LibreOJ/2669/data/foodshop15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:902da5c37ec31a1f54b1ae6ab48ac0b2a61e92c93296202f32926fbdde3a97af +size 1574888 diff --git a/LibreOJ/2669/data/foodshop16.ans b/LibreOJ/2669/data/foodshop16.ans new file mode 100644 index 00000000..b4821525 --- /dev/null +++ b/LibreOJ/2669/data/foodshop16.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbe4f235f89a7ea1f5a95b3a85bf373af6ca3fb0e77f0868eafeda1f1e8abfec +size 16 diff --git a/LibreOJ/2669/data/foodshop16.in b/LibreOJ/2669/data/foodshop16.in new file mode 100644 index 00000000..df0e8f92 --- /dev/null +++ b/LibreOJ/2669/data/foodshop16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:397c28d25f8bb45edb21be55be20b8fe6ffbed55ffcf9d3bc1c8ffdd3f97688f +size 1801557 diff --git a/LibreOJ/2669/data/foodshop17.ans b/LibreOJ/2669/data/foodshop17.ans new file mode 100644 index 00000000..e58abbb6 --- /dev/null +++ b/LibreOJ/2669/data/foodshop17.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dd60d4bbe0bfbc5f8e0568d3ca1115048b2d5699d5975e1c07d2d8c80331e3e +size 16 diff --git a/LibreOJ/2669/data/foodshop17.in b/LibreOJ/2669/data/foodshop17.in new file mode 100644 index 00000000..0105bff4 --- /dev/null +++ b/LibreOJ/2669/data/foodshop17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ed2ebf358a337dcae7a7bf89f7c89517b4bff19b0c605315baa31e1a9934ea3 +size 2257555 diff --git a/LibreOJ/2669/data/foodshop18.ans b/LibreOJ/2669/data/foodshop18.ans new file mode 100644 index 00000000..e4f1834e --- /dev/null +++ b/LibreOJ/2669/data/foodshop18.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20c71b11f5f1d496e9398a191dc6f979ca48ab5bdef1145c885821e9bbb42e74 +size 18 diff --git a/LibreOJ/2669/data/foodshop18.in b/LibreOJ/2669/data/foodshop18.in new file mode 100644 index 00000000..67135193 --- /dev/null +++ b/LibreOJ/2669/data/foodshop18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fa6e999c5850825cf403f16f87c6394dd79214807a0c76ad4fbd6cbe83262fa +size 2259357 diff --git a/LibreOJ/2669/data/foodshop19.ans b/LibreOJ/2669/data/foodshop19.ans new file mode 100644 index 00000000..d73860f0 --- /dev/null +++ b/LibreOJ/2669/data/foodshop19.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d40ed03291e0d18df9f3f7b6b11b983c40d29c72dc5572d62e3100c5b0a8684 +size 18 diff --git a/LibreOJ/2669/data/foodshop19.in b/LibreOJ/2669/data/foodshop19.in new file mode 100644 index 00000000..caba6334 --- /dev/null +++ b/LibreOJ/2669/data/foodshop19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed07e0521324c8fad8bbe01734193d6d71eafcc64563b7173ab5094edb2214fd +size 2259669 diff --git a/LibreOJ/2669/data/foodshop2.ans b/LibreOJ/2669/data/foodshop2.ans new file mode 100644 index 00000000..fa458be0 --- /dev/null +++ b/LibreOJ/2669/data/foodshop2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a140d92d74b5c263b2e062f03d8fb0379569abf92c3246cee28be7532c4ee75 +size 6 diff --git a/LibreOJ/2669/data/foodshop2.in b/LibreOJ/2669/data/foodshop2.in new file mode 100644 index 00000000..b6d7b80c --- /dev/null +++ b/LibreOJ/2669/data/foodshop2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:289ca745cbaa701c3e634504f6f70b563d48f35b3d548589a9dbdcdb836336b2 +size 704 diff --git a/LibreOJ/2669/data/foodshop20.ans b/LibreOJ/2669/data/foodshop20.ans new file mode 100644 index 00000000..8f9826c0 --- /dev/null +++ b/LibreOJ/2669/data/foodshop20.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fb74c6fd1ffeffe92e35ff17392de1fa86deee31a3a4200a3ea63bdaa8a20b6 +size 18 diff --git a/LibreOJ/2669/data/foodshop20.in b/LibreOJ/2669/data/foodshop20.in new file mode 100644 index 00000000..843fa218 --- /dev/null +++ b/LibreOJ/2669/data/foodshop20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a6bbf64ac769871ee9cd0de3f546de142ed67825669c68ee84ec2fc455926c3 +size 2259550 diff --git a/LibreOJ/2669/data/foodshop3.ans b/LibreOJ/2669/data/foodshop3.ans new file mode 100644 index 00000000..2fd49bbe --- /dev/null +++ b/LibreOJ/2669/data/foodshop3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e560b6e27ac96a310039e0aef1d40539efe38c9c0d90b8ad25e93e40717d98af +size 8 diff --git a/LibreOJ/2669/data/foodshop3.in b/LibreOJ/2669/data/foodshop3.in new file mode 100644 index 00000000..5864f049 --- /dev/null +++ b/LibreOJ/2669/data/foodshop3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e2e679c13c1a145c336af83cf399a123054e1494dbf0c90b4fdb6f8b6ebe761 +size 3365 diff --git a/LibreOJ/2669/data/foodshop4.ans b/LibreOJ/2669/data/foodshop4.ans new file mode 100644 index 00000000..c4ea48ae --- /dev/null +++ b/LibreOJ/2669/data/foodshop4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f48208572c3f7a605f10c805e5dfa239ef1b98089cfa7598103cf15e9584a8a4 +size 8 diff --git a/LibreOJ/2669/data/foodshop4.in b/LibreOJ/2669/data/foodshop4.in new file mode 100644 index 00000000..fecd8891 --- /dev/null +++ b/LibreOJ/2669/data/foodshop4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41e736b3b0d0dfd92ea28d34dd517bbe456ed9b882a354da4152b82e39dc4318 +size 4553 diff --git a/LibreOJ/2669/data/foodshop5.ans b/LibreOJ/2669/data/foodshop5.ans new file mode 100644 index 00000000..778905a7 --- /dev/null +++ b/LibreOJ/2669/data/foodshop5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0388e69d254c4e5f27e83f006fd31a2dd5cb8a3bd323166a0b9f5c0ad0903dd9 +size 9 diff --git a/LibreOJ/2669/data/foodshop5.in b/LibreOJ/2669/data/foodshop5.in new file mode 100644 index 00000000..dd1b29aa --- /dev/null +++ b/LibreOJ/2669/data/foodshop5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ae300793615b3f9e7eb9820a799fd59b6ba87a4d71a0cf2f82dcb455a69abd3 +size 6931 diff --git a/LibreOJ/2669/data/foodshop6.ans b/LibreOJ/2669/data/foodshop6.ans new file mode 100644 index 00000000..4c732ea4 --- /dev/null +++ b/LibreOJ/2669/data/foodshop6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85c6360c9d260edf826628683aab66b87e1ed4efea5089ecd71a3a50fb70c4a5 +size 8 diff --git a/LibreOJ/2669/data/foodshop6.in b/LibreOJ/2669/data/foodshop6.in new file mode 100644 index 00000000..499f9e87 --- /dev/null +++ b/LibreOJ/2669/data/foodshop6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81e9ff7c1d731a188fb2def0fe7bbf96fa1b2ec5fd5fb0fa7d53ce35c6090ca6 +size 6939 diff --git a/LibreOJ/2669/data/foodshop7.ans b/LibreOJ/2669/data/foodshop7.ans new file mode 100644 index 00000000..f880d453 --- /dev/null +++ b/LibreOJ/2669/data/foodshop7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b31aa10b714388b72c2989a5b0c9488a6bcf52a6078b564f6bcc92d4a493605 +size 15 diff --git a/LibreOJ/2669/data/foodshop7.in b/LibreOJ/2669/data/foodshop7.in new file mode 100644 index 00000000..9c6d3ffd --- /dev/null +++ b/LibreOJ/2669/data/foodshop7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca0d529ffac434bf30d8f0be10db190cdb523debcaba94ec640b9f7a7c7eb5b5 +size 18610 diff --git a/LibreOJ/2669/data/foodshop8.ans b/LibreOJ/2669/data/foodshop8.ans new file mode 100644 index 00000000..e087bf46 --- /dev/null +++ b/LibreOJ/2669/data/foodshop8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13120e7e6d19ca1165262902cabe107707f325c2ce265d747c4da39d91269b61 +size 16 diff --git a/LibreOJ/2669/data/foodshop8.in b/LibreOJ/2669/data/foodshop8.in new file mode 100644 index 00000000..969ed54b --- /dev/null +++ b/LibreOJ/2669/data/foodshop8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:919ff76a68bb7f1251f6ca628d434d5ccbe0ac0e154802f070a8900842e3e7d4 +size 29022 diff --git a/LibreOJ/2669/data/foodshop9.ans b/LibreOJ/2669/data/foodshop9.ans new file mode 100644 index 00000000..ae16e7e2 --- /dev/null +++ b/LibreOJ/2669/data/foodshop9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:382b9e56a365620d70e878fb85aa781c7d0a7815d34306c4c753643a2f0f7433 +size 14 diff --git a/LibreOJ/2669/data/foodshop9.in b/LibreOJ/2669/data/foodshop9.in new file mode 100644 index 00000000..9623adfb --- /dev/null +++ b/LibreOJ/2669/data/foodshop9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e9bf4747cc754263d5f2a24687ac44acab70029d6b9964be8047ad2f0f42c2e +size 31973