From 5277427cb210684fa931e36c8e25d284e8126271 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 29 Jan 2023 19:50:24 +0800 Subject: [PATCH] =?UTF-8?q?#1836.=20=E3=80=90CTSC2010=E3=80=91=E6=98=9F?= =?UTF-8?q?=E9=99=85=E6=97=85=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/67611 --- S2OJ/1836/1836.cpp | 84 +++++++++++++++++++++++++++++++++++++ S2OJ/1836/data/problem.conf | 3 ++ S2OJ/1836/data/travel1.in | 3 ++ S2OJ/1836/data/travel1.out | 3 ++ S2OJ/1836/data/travel10.in | 3 ++ S2OJ/1836/data/travel10.out | 3 ++ S2OJ/1836/data/travel2.in | 3 ++ S2OJ/1836/data/travel2.out | 3 ++ S2OJ/1836/data/travel3.in | 3 ++ S2OJ/1836/data/travel3.out | 3 ++ S2OJ/1836/data/travel4.in | 3 ++ S2OJ/1836/data/travel4.out | 3 ++ S2OJ/1836/data/travel5.in | 3 ++ S2OJ/1836/data/travel5.out | 3 ++ S2OJ/1836/data/travel6.in | 3 ++ S2OJ/1836/data/travel6.out | 3 ++ S2OJ/1836/data/travel7.in | 3 ++ S2OJ/1836/data/travel7.out | 3 ++ S2OJ/1836/data/travel8.in | 3 ++ S2OJ/1836/data/travel8.out | 3 ++ S2OJ/1836/data/travel9.in | 3 ++ S2OJ/1836/data/travel9.out | 3 ++ 22 files changed, 147 insertions(+) create mode 100644 S2OJ/1836/1836.cpp create mode 100644 S2OJ/1836/data/problem.conf create mode 100644 S2OJ/1836/data/travel1.in create mode 100644 S2OJ/1836/data/travel1.out create mode 100644 S2OJ/1836/data/travel10.in create mode 100644 S2OJ/1836/data/travel10.out create mode 100644 S2OJ/1836/data/travel2.in create mode 100644 S2OJ/1836/data/travel2.out create mode 100644 S2OJ/1836/data/travel3.in create mode 100644 S2OJ/1836/data/travel3.out create mode 100644 S2OJ/1836/data/travel4.in create mode 100644 S2OJ/1836/data/travel4.out create mode 100644 S2OJ/1836/data/travel5.in create mode 100644 S2OJ/1836/data/travel5.out create mode 100644 S2OJ/1836/data/travel6.in create mode 100644 S2OJ/1836/data/travel6.out create mode 100644 S2OJ/1836/data/travel7.in create mode 100644 S2OJ/1836/data/travel7.out create mode 100644 S2OJ/1836/data/travel8.in create mode 100644 S2OJ/1836/data/travel8.out create mode 100644 S2OJ/1836/data/travel9.in create mode 100644 S2OJ/1836/data/travel9.out diff --git a/S2OJ/1836/1836.cpp b/S2OJ/1836/1836.cpp new file mode 100644 index 00000000..94c15baf --- /dev/null +++ b/S2OJ/1836/1836.cpp @@ -0,0 +1,84 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 50005; + +int n, h[N], son[N], ans[N], res; +std::vector g[N]; + +void dfs1(int u, int f) { + for (int v : g[u]) { + if (v == f) continue; + + dfs1(v, u); + + int x = std::min(h[u], h[v]); + + h[u] -= x, h[v] -= x; + res += x * 2; + + if (h[v]) son[u] = v; + } +} + +void dfs2(int u, int f) { + ans[u] = res; + + for (int v : g[u]) { + if (v == f) continue; + + if (h[u]) { + h[u]--, res++; + + dfs2(v, u); + + h[u]++, res--; + } else if (son[v]) { + h[son[v]]--, res++; + + dfs2(v, u); + + h[son[v]]++, res--; + } else { + h[v]++, res--; + + dfs2(v, u); + + h[v]--, res++; + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> h[i]; + } + + for (int i = 1, x, y; i < n; i++) { + cin >> x >> y; + + h[++x]--, h[++y]--; + g[x].emplace_back(y); + g[y].emplace_back(x); + + res += 2; + } + + dfs1(1, 0); + dfs2(1, 0); + + for (int i = 1; i <= n; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/S2OJ/1836/data/problem.conf b/S2OJ/1836/data/problem.conf new file mode 100644 index 00000000..ed92a50b --- /dev/null +++ b/S2OJ/1836/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82bf988a3c45218435fb3b7418cf105e346d50d5776452e18d7a6bb0fcfc562c +size 181 diff --git a/S2OJ/1836/data/travel1.in b/S2OJ/1836/data/travel1.in new file mode 100644 index 00000000..35e540fc --- /dev/null +++ b/S2OJ/1836/data/travel1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d749211baeba65e96ed7e60dcc7c5b381be1c31f6605424a2337289c6c61d5a +size 836797 diff --git a/S2OJ/1836/data/travel1.out b/S2OJ/1836/data/travel1.out new file mode 100644 index 00000000..ec100961 --- /dev/null +++ b/S2OJ/1836/data/travel1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87ba92235d6a30fbc8e9c8837b8c674ef2856e1b8d59f3f378b5a642dd7a6584 +size 500000 diff --git a/S2OJ/1836/data/travel10.in b/S2OJ/1836/data/travel10.in new file mode 100644 index 00000000..e81f7500 --- /dev/null +++ b/S2OJ/1836/data/travel10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fcbb566a677822b725e2669492f66f557e53949bff12347128e41e030ca40f8 +size 6412 diff --git a/S2OJ/1836/data/travel10.out b/S2OJ/1836/data/travel10.out new file mode 100644 index 00000000..8a13eece --- /dev/null +++ b/S2OJ/1836/data/travel10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a32d4f08a9631cbb9dd1e9ef89be67596cbba358f5112fe3167997f458da1df1 +size 4000 diff --git a/S2OJ/1836/data/travel2.in b/S2OJ/1836/data/travel2.in new file mode 100644 index 00000000..e622c661 --- /dev/null +++ b/S2OJ/1836/data/travel2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d45e292bd502c1b32bb49f5061aa84eea0679a6d8a315ead4688d638992002db +size 836673 diff --git a/S2OJ/1836/data/travel2.out b/S2OJ/1836/data/travel2.out new file mode 100644 index 00000000..277cd976 --- /dev/null +++ b/S2OJ/1836/data/travel2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5858e22c504294c882c2dce817add67d5e0405f913e50161b88d784d65adae31 +size 500000 diff --git a/S2OJ/1836/data/travel3.in b/S2OJ/1836/data/travel3.in new file mode 100644 index 00000000..1b099601 --- /dev/null +++ b/S2OJ/1836/data/travel3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d6ad9cb325db48c09c26a8eadd451cc4e1579936e92146026216a9891888a97 +size 837073 diff --git a/S2OJ/1836/data/travel3.out b/S2OJ/1836/data/travel3.out new file mode 100644 index 00000000..be028b20 --- /dev/null +++ b/S2OJ/1836/data/travel3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb761bbcfb7e8996e2838554b78c2c5a2ac956da9646de222256dff601150a90 +size 500000 diff --git a/S2OJ/1836/data/travel4.in b/S2OJ/1836/data/travel4.in new file mode 100644 index 00000000..d531f375 --- /dev/null +++ b/S2OJ/1836/data/travel4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d78841f5b7597c2ff12fa413b2993f0d550efdc2a558d49fb3693adc72d22d06 +size 6397 diff --git a/S2OJ/1836/data/travel4.out b/S2OJ/1836/data/travel4.out new file mode 100644 index 00000000..f4db745c --- /dev/null +++ b/S2OJ/1836/data/travel4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1e3cafd377c93ad72a3cda1a7d5c27cc3c62605de36ebff795fde4d497ece28 +size 4000 diff --git a/S2OJ/1836/data/travel5.in b/S2OJ/1836/data/travel5.in new file mode 100644 index 00000000..6d44b38f --- /dev/null +++ b/S2OJ/1836/data/travel5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce4804cb50631829d3f5a59e6b4b2d71bed28e5a63988cb9ea42a73e85f1d6a9 +size 6423 diff --git a/S2OJ/1836/data/travel5.out b/S2OJ/1836/data/travel5.out new file mode 100644 index 00000000..11239762 --- /dev/null +++ b/S2OJ/1836/data/travel5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae0ce30772a169d6da45de13713a65760ff986f359e5c24533cb2a3848e7eed5 +size 4000 diff --git a/S2OJ/1836/data/travel6.in b/S2OJ/1836/data/travel6.in new file mode 100644 index 00000000..d1dc0769 --- /dev/null +++ b/S2OJ/1836/data/travel6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f0f36068c468050f0e11b312d2b5b5d4e1f7748a7c7a7e59ee00ca1562cf7c1 +size 6418 diff --git a/S2OJ/1836/data/travel6.out b/S2OJ/1836/data/travel6.out new file mode 100644 index 00000000..5dbf1c69 --- /dev/null +++ b/S2OJ/1836/data/travel6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0835e9a605d78a2aee3e3087b8aa6c74db42de7c71274e235408a85f80e1e4ea +size 4000 diff --git a/S2OJ/1836/data/travel7.in b/S2OJ/1836/data/travel7.in new file mode 100644 index 00000000..8a204e11 --- /dev/null +++ b/S2OJ/1836/data/travel7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:682461cb94577a597463e4a13feb1d5c74d23fbc9fb0d9ced2deee831f03a2cd +size 836798 diff --git a/S2OJ/1836/data/travel7.out b/S2OJ/1836/data/travel7.out new file mode 100644 index 00000000..468b6863 --- /dev/null +++ b/S2OJ/1836/data/travel7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a65bfbdfba7003969ad8d37285525a3359286069b50db423d61aa99dc46be32b +size 500000 diff --git a/S2OJ/1836/data/travel8.in b/S2OJ/1836/data/travel8.in new file mode 100644 index 00000000..1bb9e34f --- /dev/null +++ b/S2OJ/1836/data/travel8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8154285443884265c431e47449c645f9752b0293c93c14e48e050d55f9b795af +size 836820 diff --git a/S2OJ/1836/data/travel8.out b/S2OJ/1836/data/travel8.out new file mode 100644 index 00000000..e5194e4c --- /dev/null +++ b/S2OJ/1836/data/travel8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c0ef96d2cf6ad9fa559ef4927d70ee56c70be0f59e7bc5296b2f35eb250a6ca +size 500000 diff --git a/S2OJ/1836/data/travel9.in b/S2OJ/1836/data/travel9.in new file mode 100644 index 00000000..adf9f86f --- /dev/null +++ b/S2OJ/1836/data/travel9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:586babefdad5429e5bc61f8d3c26f72f3ec91fe02a503ada84f4b12c694168ad +size 836660 diff --git a/S2OJ/1836/data/travel9.out b/S2OJ/1836/data/travel9.out new file mode 100644 index 00000000..099fa4bd --- /dev/null +++ b/S2OJ/1836/data/travel9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0efa4b2c5e397b8933ce8eb9cc3e413e58be138500e9d83dd41bab6ba53773a +size 500000