From 1a5233b4cbeca5341def473b04162403d57bd4d6 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 17:23:06 +0800 Subject: [PATCH] =?UTF-8?q?1015.=20[JSOI2008]=E6=98=9F=E7=90=83=E5=A4=A7?= =?UTF-8?q?=E6=88=98starwar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/6322eed632ae6c3198cc9fa0 --- BZOJ/1015/1015.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/1015/data/1.in | 3 ++ BZOJ/1015/data/1.out | 3 ++ BZOJ/1015/data/10.in | 3 ++ BZOJ/1015/data/10.out | 3 ++ BZOJ/1015/data/2.in | 3 ++ BZOJ/1015/data/2.out | 3 ++ BZOJ/1015/data/3.in | 3 ++ BZOJ/1015/data/3.out | 3 ++ BZOJ/1015/data/4.in | 3 ++ BZOJ/1015/data/4.out | 3 ++ BZOJ/1015/data/5.in | 3 ++ BZOJ/1015/data/5.out | 3 ++ BZOJ/1015/data/6.in | 3 ++ BZOJ/1015/data/6.out | 3 ++ BZOJ/1015/data/7.in | 3 ++ BZOJ/1015/data/7.out | 3 ++ BZOJ/1015/data/8.in | 3 ++ BZOJ/1015/data/8.out | 3 ++ BZOJ/1015/data/9.in | 3 ++ BZOJ/1015/data/9.out | 3 ++ 21 files changed, 144 insertions(+) create mode 100644 BZOJ/1015/1015.cpp create mode 100644 BZOJ/1015/data/1.in create mode 100644 BZOJ/1015/data/1.out create mode 100644 BZOJ/1015/data/10.in create mode 100644 BZOJ/1015/data/10.out create mode 100644 BZOJ/1015/data/2.in create mode 100644 BZOJ/1015/data/2.out create mode 100644 BZOJ/1015/data/3.in create mode 100644 BZOJ/1015/data/3.out create mode 100644 BZOJ/1015/data/4.in create mode 100644 BZOJ/1015/data/4.out create mode 100644 BZOJ/1015/data/5.in create mode 100644 BZOJ/1015/data/5.out create mode 100644 BZOJ/1015/data/6.in create mode 100644 BZOJ/1015/data/6.out create mode 100644 BZOJ/1015/data/7.in create mode 100644 BZOJ/1015/data/7.out create mode 100644 BZOJ/1015/data/8.in create mode 100644 BZOJ/1015/data/8.out create mode 100644 BZOJ/1015/data/9.in create mode 100644 BZOJ/1015/data/9.out diff --git a/BZOJ/1015/1015.cpp b/BZOJ/1015/1015.cpp new file mode 100644 index 00000000..160836b9 --- /dev/null +++ b/BZOJ/1015/1015.cpp @@ -0,0 +1,84 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 4e5 + 5; + +int n, m, k, a[N], fa[N], ans[N]; +bool vis[N], del[N]; +std::vector g[N]; + +int find(int x) { + return fa[x] == x ? x : fa[x] = find(fa[x]); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 0, x, y; i < m; i++) { + cin >> x >> y; + + g[x].push_back(y); + g[y].push_back(x); + } + + for (int i = 0; i < n; i++) fa[i] = i; + + cin >> k; + + for (int i = 1; i <= k; i++) { + cin >> a[i]; + + del[a[i]] = true; + } + + for (int i = 0; i < n; i++) { + if (!del[i]) { + for (int v : g[i]) { + if (!del[v]) { + int f1 = find(i), + f2 = find(v); + + fa[f1] = f2; + } + } + } + } + + int cnt = 0; + for (int i = 0; i < n; i++) { + if (fa[i] == i && !del[i]) cnt++; + } + ans[k] = cnt; + + for (int i = k; i; i--) { + del[a[i]] = false; + cnt++; + + for (int v : g[a[i]]) { + if (!del[v]) { + int f1 = find(a[i]), + f2 = find(v); + + if (f1 != f2) { + fa[f1] = f2; + cnt--; + } + } + } + + ans[i - 1] = cnt; + } + + for (int i = 0; i <= k; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/BZOJ/1015/data/1.in b/BZOJ/1015/data/1.in new file mode 100644 index 00000000..0b2ab5cf --- /dev/null +++ b/BZOJ/1015/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44b32e6520f1c2ad3dd58537eec744fea92209fdebf5b57616fa5e34b180877f +size 3867242 diff --git a/BZOJ/1015/data/1.out b/BZOJ/1015/data/1.out new file mode 100644 index 00000000..0e69fc0d --- /dev/null +++ b/BZOJ/1015/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c82750a5b03c3ac30b2d3d7681e2145045e69815e6754bbdfda746c9c3a4c268 +size 1188361 diff --git a/BZOJ/1015/data/10.in b/BZOJ/1015/data/10.in new file mode 100644 index 00000000..24e3336d --- /dev/null +++ b/BZOJ/1015/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3152f3a168bb58a982cdcbeb860a4fe81486131992090966db67c9a7da6646d +size 3545270 diff --git a/BZOJ/1015/data/10.out b/BZOJ/1015/data/10.out new file mode 100644 index 00000000..ebf27ca8 --- /dev/null +++ b/BZOJ/1015/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6f756518fd5a3080c671f242abdcf07e5e6a0853e0de202ac2218f5f132ebf5 +size 900006 diff --git a/BZOJ/1015/data/2.in b/BZOJ/1015/data/2.in new file mode 100644 index 00000000..1c1c7463 --- /dev/null +++ b/BZOJ/1015/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1181005f2c4853f56ef61dc66704d05b3b3585bd2b62ac9e99d99ba07fddf4b6 +size 980394 diff --git a/BZOJ/1015/data/2.out b/BZOJ/1015/data/2.out new file mode 100644 index 00000000..c3645733 --- /dev/null +++ b/BZOJ/1015/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9642910dbbcbe8645f5836aa3cd4b219e0bdcdad8d20c6277708dad3c527d4b +size 1753 diff --git a/BZOJ/1015/data/3.in b/BZOJ/1015/data/3.in new file mode 100644 index 00000000..91c18a6d --- /dev/null +++ b/BZOJ/1015/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a72e378bf49dbb32a9ff62371ccc33b5af94f90c3854400bb4fc0002266e231 +size 69 diff --git a/BZOJ/1015/data/3.out b/BZOJ/1015/data/3.out new file mode 100644 index 00000000..5ae3454f --- /dev/null +++ b/BZOJ/1015/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9c537986e1fbdf32191ce4f217c3e228a0ff0a56e838e905f658e70d218f84d +size 22 diff --git a/BZOJ/1015/data/4.in b/BZOJ/1015/data/4.in new file mode 100644 index 00000000..ee3286b7 --- /dev/null +++ b/BZOJ/1015/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c781862b1e05d1fce7d725b5dc36928280146f2d5eed93b9b539275aaf36f20 +size 2489441 diff --git a/BZOJ/1015/data/4.out b/BZOJ/1015/data/4.out new file mode 100644 index 00000000..258ca577 --- /dev/null +++ b/BZOJ/1015/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a8e98fec18ac398973f8c26fd3c0651143452d3d17018b2b6d30158a7916fbd +size 119974 diff --git a/BZOJ/1015/data/5.in b/BZOJ/1015/data/5.in new file mode 100644 index 00000000..7fedab36 --- /dev/null +++ b/BZOJ/1015/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbfb9963204ba06bf6b218c0370074b792aa5106023e8d9520ee991043dff229 +size 3866696 diff --git a/BZOJ/1015/data/5.out b/BZOJ/1015/data/5.out new file mode 100644 index 00000000..1f087734 --- /dev/null +++ b/BZOJ/1015/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a97c029661feea9bec238e3336ac594aef00694e2886547651d7bdaa0506a560 +size 1176725 diff --git a/BZOJ/1015/data/6.in b/BZOJ/1015/data/6.in new file mode 100644 index 00000000..27c89865 --- /dev/null +++ b/BZOJ/1015/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f849df4c565f4a1af3dbb2a6cc4a2afd06be246b83bbb26af2c867ff132d6f3 +size 38 diff --git a/BZOJ/1015/data/6.out b/BZOJ/1015/data/6.out new file mode 100644 index 00000000..99b62fc2 --- /dev/null +++ b/BZOJ/1015/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a497679f6064a5f761dfb6015a6a0efbb6087097348a0cd35e36db30ea663f14 +size 10 diff --git a/BZOJ/1015/data/7.in b/BZOJ/1015/data/7.in new file mode 100644 index 00000000..eef51589 --- /dev/null +++ b/BZOJ/1015/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8eb0fa1cbecb5c7e298974176952e14182111e6888395e355c909485977221dc +size 1980098 diff --git a/BZOJ/1015/data/7.out b/BZOJ/1015/data/7.out new file mode 100644 index 00000000..808a798a --- /dev/null +++ b/BZOJ/1015/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb6c0c814df289da0fffef0d3948a185e90ddd4cc8985d153bdae007570d06d0 +size 10002 diff --git a/BZOJ/1015/data/8.in b/BZOJ/1015/data/8.in new file mode 100644 index 00000000..11ce07d9 --- /dev/null +++ b/BZOJ/1015/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:686c17e493fbd57d9e5a93f6cb7dce12c0e00dee26e291921074ff1e50b25bbc +size 4033243 diff --git a/BZOJ/1015/data/8.out b/BZOJ/1015/data/8.out new file mode 100644 index 00000000..1a68ed6f --- /dev/null +++ b/BZOJ/1015/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08153380c1e714221ae5b38dddc9a78a663a866a5e3681e19da9e35d74a908c9 +size 1400007 diff --git a/BZOJ/1015/data/9.in b/BZOJ/1015/data/9.in new file mode 100644 index 00000000..b8447758 --- /dev/null +++ b/BZOJ/1015/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24e91eb98febe592290716cbdbc13ff06c5f621b62846a02086143e15a27f455 +size 2025209 diff --git a/BZOJ/1015/data/9.out b/BZOJ/1015/data/9.out new file mode 100644 index 00000000..25c2478a --- /dev/null +++ b/BZOJ/1015/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10ced0a76f384688fa09007e79dd674435176c1f7ef52d3ec186c465850d3008 +size 271562