From b238b8ee8b3bd2aa0c98a3fbb3ad447cbd15831b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 20 Sep 2022 21:37:38 +0800 Subject: [PATCH] 1123. [POI2008]BLO https://hydro.ac/d/bzoj/record/6329c21479b7c59ccd1f3d9e --- BZOJ/1123/1123.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/1123/data/1.in | 3 ++ BZOJ/1123/data/1.out | 3 ++ BZOJ/1123/data/10.in | 3 ++ BZOJ/1123/data/10.out | 3 ++ BZOJ/1123/data/11.in | 3 ++ BZOJ/1123/data/11.out | 3 ++ BZOJ/1123/data/12.in | 3 ++ BZOJ/1123/data/12.out | 3 ++ BZOJ/1123/data/13.in | 3 ++ BZOJ/1123/data/13.out | 3 ++ BZOJ/1123/data/14.in | 3 ++ BZOJ/1123/data/14.out | 3 ++ BZOJ/1123/data/15.in | 3 ++ BZOJ/1123/data/15.out | 3 ++ BZOJ/1123/data/16.in | 3 ++ BZOJ/1123/data/16.out | 3 ++ BZOJ/1123/data/2.in | 3 ++ BZOJ/1123/data/2.out | 3 ++ BZOJ/1123/data/3.in | 3 ++ BZOJ/1123/data/3.out | 3 ++ BZOJ/1123/data/4.in | 3 ++ BZOJ/1123/data/4.out | 3 ++ BZOJ/1123/data/5.in | 3 ++ BZOJ/1123/data/5.out | 3 ++ BZOJ/1123/data/6.in | 3 ++ BZOJ/1123/data/6.out | 3 ++ BZOJ/1123/data/7.in | 3 ++ BZOJ/1123/data/7.out | 3 ++ BZOJ/1123/data/8.in | 3 ++ BZOJ/1123/data/8.out | 3 ++ BZOJ/1123/data/9.in | 3 ++ BZOJ/1123/data/9.out | 3 ++ 33 files changed, 173 insertions(+) create mode 100644 BZOJ/1123/1123.cpp create mode 100644 BZOJ/1123/data/1.in create mode 100644 BZOJ/1123/data/1.out create mode 100644 BZOJ/1123/data/10.in create mode 100644 BZOJ/1123/data/10.out create mode 100644 BZOJ/1123/data/11.in create mode 100644 BZOJ/1123/data/11.out create mode 100644 BZOJ/1123/data/12.in create mode 100644 BZOJ/1123/data/12.out create mode 100644 BZOJ/1123/data/13.in create mode 100644 BZOJ/1123/data/13.out create mode 100644 BZOJ/1123/data/14.in create mode 100644 BZOJ/1123/data/14.out create mode 100644 BZOJ/1123/data/15.in create mode 100644 BZOJ/1123/data/15.out create mode 100644 BZOJ/1123/data/16.in create mode 100644 BZOJ/1123/data/16.out create mode 100644 BZOJ/1123/data/2.in create mode 100644 BZOJ/1123/data/2.out create mode 100644 BZOJ/1123/data/3.in create mode 100644 BZOJ/1123/data/3.out create mode 100644 BZOJ/1123/data/4.in create mode 100644 BZOJ/1123/data/4.out create mode 100644 BZOJ/1123/data/5.in create mode 100644 BZOJ/1123/data/5.out create mode 100644 BZOJ/1123/data/6.in create mode 100644 BZOJ/1123/data/6.out create mode 100644 BZOJ/1123/data/7.in create mode 100644 BZOJ/1123/data/7.out create mode 100644 BZOJ/1123/data/8.in create mode 100644 BZOJ/1123/data/8.out create mode 100644 BZOJ/1123/data/9.in create mode 100644 BZOJ/1123/data/9.out diff --git a/BZOJ/1123/1123.cpp b/BZOJ/1123/1123.cpp new file mode 100644 index 00000000..43e753ff --- /dev/null +++ b/BZOJ/1123/1123.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m; +long long ans[N]; +std::vector g[N]; +int root, cnt, dfn[N], low[N], siz[N]; +bool cut[N]; + +void tarjan(int u) { + dfn[u] = low[u] = ++cnt; + siz[u] = 1; + + bool flag = false; + int sum = 0; + + for (int v : g[u]) { + if (!dfn[v]) { + tarjan(v); + low[u] = std::min(low[u], low[v]); + siz[u] += siz[v]; + + if (dfn[u] <= low[v]) { + if (u != root || flag) { + cut[u] = true; + sum += siz[v]; + ans[u] += static_cast(n - siz[v]) * siz[v]; + } else { + flag = true; + } + } + } else { + low[u] = std::min(low[u], dfn[v]); + } + } + + if (cut[u]) { + ans[u] += static_cast(n - sum - 1) * (sum + 1) + + n - 1; + } else { + ans[u] = 2 * (n - 1); + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + g[u].emplace_back(v); + g[v].emplace_back(u); + } + + for (int i = 1; i <= n; i++) { + if (!dfn[i]) { + root = i; + tarjan(i); + } + } + + for (int i = 1; i <= n; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/BZOJ/1123/data/1.in b/BZOJ/1123/data/1.in new file mode 100644 index 00000000..5a68e1a7 --- /dev/null +++ b/BZOJ/1123/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87ca9ebe40d1e27f9a278c650533e0160ee259780522422013136c328090b645 +size 20 diff --git a/BZOJ/1123/data/1.out b/BZOJ/1123/data/1.out new file mode 100644 index 00000000..34090924 --- /dev/null +++ b/BZOJ/1123/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c0d0a40c2c735fdc8c73ee36cb9253c532269c3d916c9fa8cd00d3eff2aa2ec +size 11 diff --git a/BZOJ/1123/data/10.in b/BZOJ/1123/data/10.in new file mode 100644 index 00000000..6a7c633b --- /dev/null +++ b/BZOJ/1123/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3cf59400b9acc9d5a05089f538ceb5fef30c236d64b4f2424db6d4f1561f6a0e +size 1177791 diff --git a/BZOJ/1123/data/10.out b/BZOJ/1123/data/10.out new file mode 100644 index 00000000..7f69d013 --- /dev/null +++ b/BZOJ/1123/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64a4f8a5fe8234e297fa663f28d539cd3c18c50a6d35c0c04ae417370c6ca94a +size 1088330 diff --git a/BZOJ/1123/data/11.in b/BZOJ/1123/data/11.in new file mode 100644 index 00000000..6c4bef11 --- /dev/null +++ b/BZOJ/1123/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22b8051cedc8512b4972bcf1cc358d4b7a2ddcf8c6e567dae81ef3df82613b04 +size 896412 diff --git a/BZOJ/1123/data/11.out b/BZOJ/1123/data/11.out new file mode 100644 index 00000000..2c781066 --- /dev/null +++ b/BZOJ/1123/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:323d2fc2ecee4c000a69091326e9ac9de853c3e2a4d9acbfdcbf1c75b276a24e +size 60076 diff --git a/BZOJ/1123/data/12.in b/BZOJ/1123/data/12.in new file mode 100644 index 00000000..d14f24a7 --- /dev/null +++ b/BZOJ/1123/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52543b4e57c045cf06bf27a6bf6474adbe76204992391b815383682f877d193c +size 76115 diff --git a/BZOJ/1123/data/12.out b/BZOJ/1123/data/12.out new file mode 100644 index 00000000..2a0113b8 --- /dev/null +++ b/BZOJ/1123/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d878815e92c1ead94bfbf6115ce8078af22b7284c16c2e69e802136848e636b7 +size 2046 diff --git a/BZOJ/1123/data/13.in b/BZOJ/1123/data/13.in new file mode 100644 index 00000000..83cb46dd --- /dev/null +++ b/BZOJ/1123/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26a81d7e03bd85845fd492c1a43d2371e1c1121060d9670a615a0a35303de1b4 +size 4156257 diff --git a/BZOJ/1123/data/13.out b/BZOJ/1123/data/13.out new file mode 100644 index 00000000..284825c2 --- /dev/null +++ b/BZOJ/1123/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81d3cd47405828bd0340a19c1a21f245f4542627a47f036c43259e7ba67c06b0 +size 700164 diff --git a/BZOJ/1123/data/14.in b/BZOJ/1123/data/14.in new file mode 100644 index 00000000..8897a49c --- /dev/null +++ b/BZOJ/1123/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2236187e62ef2f24b75cb55a6abc7810dda10f068d0decd4f71ce09c519216e +size 272 diff --git a/BZOJ/1123/data/14.out b/BZOJ/1123/data/14.out new file mode 100644 index 00000000..903e6106 --- /dev/null +++ b/BZOJ/1123/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b77d5a47526219b6bc81831c0778f8878c56adce79b9e4e028e3b8e5748e37c +size 95 diff --git a/BZOJ/1123/data/15.in b/BZOJ/1123/data/15.in new file mode 100644 index 00000000..c7a848d7 --- /dev/null +++ b/BZOJ/1123/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b75aa31607154d84a3ade565ebce5a6f2e29e6b87ad4811d25c6dec522341333 +size 28 diff --git a/BZOJ/1123/data/15.out b/BZOJ/1123/data/15.out new file mode 100644 index 00000000..16a4c248 --- /dev/null +++ b/BZOJ/1123/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d3738f9e06042f3f4fed7a91cbaab4ff280d61da8428db5bb9a4431564074fe +size 18 diff --git a/BZOJ/1123/data/16.in b/BZOJ/1123/data/16.in new file mode 100644 index 00000000..30f947ed --- /dev/null +++ b/BZOJ/1123/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07f0c63bef0e02cfaefcec3520788e5f418900925e82ee3a15a1ea6726dce461 +size 53 diff --git a/BZOJ/1123/data/16.out b/BZOJ/1123/data/16.out new file mode 100644 index 00000000..a4d03874 --- /dev/null +++ b/BZOJ/1123/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f287b7dcd3abee3277b4cb534ae74ed225fa8cafb1d087cb8873a52b335c0f5 +size 24 diff --git a/BZOJ/1123/data/2.in b/BZOJ/1123/data/2.in new file mode 100644 index 00000000..5ebce651 --- /dev/null +++ b/BZOJ/1123/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:328b0abcb5dfb8ff14d3fcbee7e3cb4b891971cd2a973fc7127f66472b6835e7 +size 5999 diff --git a/BZOJ/1123/data/2.out b/BZOJ/1123/data/2.out new file mode 100644 index 00000000..d29f3908 --- /dev/null +++ b/BZOJ/1123/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:74aecfdc4a931663b4bb687be2fbfc79f498946b3225abf4c368ebd11b79421c +size 1017 diff --git a/BZOJ/1123/data/3.in b/BZOJ/1123/data/3.in new file mode 100644 index 00000000..98b9a3d3 --- /dev/null +++ b/BZOJ/1123/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:507717e51c5b6a9015b3f39ea752da1ad2849635af248357e6eb381861505437 +size 45 diff --git a/BZOJ/1123/data/3.out b/BZOJ/1123/data/3.out new file mode 100644 index 00000000..8fdbb681 --- /dev/null +++ b/BZOJ/1123/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4c0732df3ffe8aa4e0c484c41554cf05104facc9dfa15314ca58bf90c3a41d6 +size 10 diff --git a/BZOJ/1123/data/4.in b/BZOJ/1123/data/4.in new file mode 100644 index 00000000..ada25cc4 --- /dev/null +++ b/BZOJ/1123/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7219e739ac6abf6a39e141de2cb2077c9232bf435e87f0480dfa0c026523e347 +size 8 diff --git a/BZOJ/1123/data/4.out b/BZOJ/1123/data/4.out new file mode 100644 index 00000000..c5b76c79 --- /dev/null +++ b/BZOJ/1123/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d58f634a5b5051db5ee0bb9d005779b382be410e8ebd5144590f2f0429f9220 +size 4 diff --git a/BZOJ/1123/data/5.in b/BZOJ/1123/data/5.in new file mode 100644 index 00000000..7bfeba5f --- /dev/null +++ b/BZOJ/1123/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b66b7942161b6211eacfcb566e4909ad9f654823257f1c2f6f1cbaeab88641a1 +size 5956985 diff --git a/BZOJ/1123/data/5.out b/BZOJ/1123/data/5.out new file mode 100644 index 00000000..0a3b301c --- /dev/null +++ b/BZOJ/1123/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:143f9b273e4686b4e950080e65dedd4b8d89660e80c2b7f466db7537d366a694 +size 700311 diff --git a/BZOJ/1123/data/6.in b/BZOJ/1123/data/6.in new file mode 100644 index 00000000..7fdfee11 --- /dev/null +++ b/BZOJ/1123/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa6dd49537655fef343c18afdf41fc36e8556064bc2ad5dd7a2590139d4a51b6 +size 1156517 diff --git a/BZOJ/1123/data/6.out b/BZOJ/1123/data/6.out new file mode 100644 index 00000000..fa3b9db5 --- /dev/null +++ b/BZOJ/1123/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45f912c19cde0ce2679689ff8b635d7d2f2f05668e07ef3972e71765e93e0dcf +size 242874 diff --git a/BZOJ/1123/data/7.in b/BZOJ/1123/data/7.in new file mode 100644 index 00000000..5127925f --- /dev/null +++ b/BZOJ/1123/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dde54546d50a29df5c374f7614da28f515921d931aa7baa0f82d325382257f7d +size 887 diff --git a/BZOJ/1123/data/7.out b/BZOJ/1123/data/7.out new file mode 100644 index 00000000..3a7d2885 --- /dev/null +++ b/BZOJ/1123/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:779bd870bf05c751cc10276831606c8e4c00cf3b5aabaaebd1cb5e181ce0b463 +size 400 diff --git a/BZOJ/1123/data/8.in b/BZOJ/1123/data/8.in new file mode 100644 index 00000000..46459323 --- /dev/null +++ b/BZOJ/1123/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9009bd9b2465b984577ffddb237194abc0e643de296a94859ce42ed2f95f76f +size 2355312 diff --git a/BZOJ/1123/data/8.out b/BZOJ/1123/data/8.out new file mode 100644 index 00000000..07a65fec --- /dev/null +++ b/BZOJ/1123/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18fd899d763a1a06d8abc90fb58b3da640347e0a624c7431d6c6e3fd612659fc +size 700002 diff --git a/BZOJ/1123/data/9.in b/BZOJ/1123/data/9.in new file mode 100644 index 00000000..991f65d6 --- /dev/null +++ b/BZOJ/1123/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:816ab4d7d13eb7eb429fde1caf9c2d4b7b15adec6f7f02be96646624fe62caf7 +size 24 diff --git a/BZOJ/1123/data/9.out b/BZOJ/1123/data/9.out new file mode 100644 index 00000000..33b70a51 --- /dev/null +++ b/BZOJ/1123/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:faa2b6d60acc224466d0614f6f33298e3a14803b3562e6ce3a191617f944d5d1 +size 12