From d7c1104f8b17b9a1a27c77c76e29d58f04e63b8b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 28 Oct 2022 11:03:46 +0800 Subject: [PATCH] =?UTF-8?q?P3388=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E5=89=B2=E7=82=B9=EF=BC=88=E5=89=B2=E9=A1=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/91855549 --- Luogu/P3388/P3388.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Luogu/P3388/P3388.cpp b/Luogu/P3388/P3388.cpp index aa08af5a..be75a5bb 100644 --- a/Luogu/P3388/P3388.cpp +++ b/Luogu/P3388/P3388.cpp @@ -1,23 +1,22 @@ #include +#include #include using std::cin; using std::cout; -using std::endl; +const char endl = '\n'; -const int N = 20005; +const int N = 2e4 + 5; -int n, m, x, y; -std::vector ans, g[N]; - -// Tarjan -int cnt, dfn[N], low[N]; -int root; +int n, m; +std::vector g[N]; +int root, cnt, dfn[N], low[N]; bool cut[N]; void tarjan(int u) { dfn[u] = low[u] = ++cnt; bool flag = false; + for (int v : g[u]) { if (!dfn[v]) { tarjan(v); @@ -36,27 +35,34 @@ void tarjan(int u) { } int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + cin >> n >> m; - for (int i = 1; i <= m; i++) { + + for (int i = 1, x, y; i <= m; i++) { cin >> x >> y; - g[x].push_back(y); - g[y].push_back(x); + + g[x].emplace_back(y); + g[y].emplace_back(x); } + for (int i = 1; i <= n; i++) { if (!dfn[i]) { root = i; tarjan(i); } } + + cout << std::count(cut + 1, cut + n + 1, true) << endl; + for (int i = 1; i <= n; i++) { if (cut[i]) { - ans.push_back(i); + cout << i << ' '; } } - cout << ans.size() << endl; - for (int i : ans) { - cout << i << ' '; - } + cout << endl; + return 0; }