From eb9b66ed48e1810e9cbb2406824c61ec62124a31 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 18 Aug 2022 21:13:55 +0800 Subject: [PATCH] P3452 [POI2007]BIU-Offices https://www.luogu.com.cn/record/84334446 --- Luogu/P3452/P3452.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Luogu/P3452/P3452.cpp diff --git a/Luogu/P3452/P3452.cpp b/Luogu/P3452/P3452.cpp new file mode 100644 index 00000000..b86bbdd7 --- /dev/null +++ b/Luogu/P3452/P3452.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, cnt, ans[N]; +std::vector g[N]; +std::set set; +bool vis[N]; + +void bfs(int x) { + std::queue q; + + set.erase(x); + q.push(x); + ans[cnt]++; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + vis[u] = true; + + for (auto it = set.begin(); it != set.end();) { + int v = *it; + + if (*std::lower_bound(g[u].begin(), g[u].end(), v) != v) { + q.push(v); + ans[cnt]++; + set.erase(it++); + } else { + it++; + } + } + } +} + +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].push_back(v); + g[v].push_back(u); + } + + std::for_each(g + 1, g + n + 1, [&](auto& v) { std::sort(v.begin(), v.end()); }); + + for (int i = 1; i <= n; i++) { + set.insert(i); + } + + for (int i = 1; i <= n; i++) { + if (!vis[i]) { + cnt++; + bfs(i); + } + } + + std::sort(ans + 1, ans + 1 + cnt); + + cout << cnt << endl; + + for (int i = 1; i <= cnt; i++) { + cout << ans[i] << ' '; + } + + cout << endl; + + return 0; +}