求助怎么一直MLE
查看原帖
求助怎么一直MLE
593427
CZB59楼主2023/7/19 10:03
#include<bits/stdc++.h>
using namespace std;
const int mx=50000;
int n,m,tim=1,tp=1,ag,l,po[mx],pa[mx];
int dfn[mx],low[mx],a[10001][10001],ans[mx],fa[mx],book[mx],k[100];
void dfs(int x)
{
	int child=0;
	dfn[x]=low[x]=tim++;
	for(int y=1;y<=n;y++)
	{
		if(a[x][y])
		{
			if(!dfn[y])
			{
				child++;
				fa[y]=x;
				dfs(y);
				if(fa[x]==-1&&child>=2&&!book[x])
				{
					ans[++ag]=x;
					book[x]=1;
				}
				else if(fa[x]!=-1&&low[y]>=dfn[x]&&!book[x])
				{
					ans[++ag]=x;
					book[x]=1;
				}
//				if(low[y]>dfn[x])
				low[x]=min(low[x],low[y]);
			}
			else if(y!=fa[x])low[x]=min(low[x],dfn[y]);
		}
	}
}
int main()
{
	cin >> n >> m;
	for(int i=1;i<mx;i++)
	fa[i]=-1;
	fa[0]=0;
	for(int i=1;i<=m;i++)
	{

		cin >> po[i] >> pa[i];
		a[po[i]][pa[i]]=1;
		a[pa[i]][po[i]]=1;
	}
	for(int i=1;i<=n;i++)if(dfn[i]==0)dfs(i);
	sort(ans+1,ans+ag+1);
//	cout << ag << endl; 
//	for(int i=1;i<=ag;i++)cout << ans[i] << " ";
	
	return 0;
}
/*
8 9
1 2
1 3
2 3
2 4
3 4
4 5
5 7
5 8
6 8
*/
2023/7/19 10:03
加载中...