听灌佬多
  • 板块灌水区
  • 楼主Ethan_tang
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/11 21:04
  • 上次更新2025/1/12 09:55:47
查看原帖
听灌佬多
1491661
Ethan_tang楼主2025/1/11 21:04

P3388,跟题解打过了,第11个点RE,求助。

#include <bits/stdc++.h>
using namespace std;
int n,m,dfn[10005],low[10005],idx,cnt,head;
bool vis[10005],ans[10005];
vector <int> q[10005];
void dfs(int x)
{
	vis[x] = 1;
	dfn[x] = ++idx;
	low[x] = idx;
	int son = 0;
	for (int i = 0;i < q[x].size();i++)
	{
		if (!vis[q[x][i]])
		{
			son++;
			dfs(q[x][i]);
			low[x] = min(low[x],low[q[x][i]]);
			if (low[q[x][i]] >= dfn[x] && x != head)
			{
				cnt += !ans[x];
				ans[x] = 1;
			}
		}
		else
		{
			low[x] = min(low[x],dfn[q[x][i]]);	
		}
	}
	if (son >= 2 && x == head)
	{
		cnt += !ans[x];
		ans[x] = 1;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0;i < m;i++)
	{
		int x,y;
		cin >> x >> y;
		q[x].push_back(y);
		q[y].push_back(x);	
	}
	for (int i = 1;i <= n;i++) head = i,dfs(i);
	cout << cnt << endl;
	for (int i = 1;i <= n;i++) if (ans[i]) cout << i << " ";
	return 0;
}
2025/1/11 21:04
加载中...