RE 求助
查看原帖
RE 求助
545986
Jerrycyx楼主2022/5/10 22:19

评测记录\fcolorbox{black}{white}{评测记录}

代码:

#include<cstdio>
#include<stack>
#include<cstring>
#include<algorithm>

#define N 10005
#define M 100005

using namespace std;

int n,m;

int from[M],to[M];

struct Allan{
	int from,to;
	int next;
}edge[M];
int tot=0;
int head[M];

int value[N];

int dfn[N];
int low[N];
stack<int>sta;
int num=0;
int color[N];
int cnt=0;
int sum[N];

int f[N];
int ans=0;

void add(int from,int to)
{
	tot++;
	edge[tot].from=from;
	edge[tot].to=to;
	edge[tot].next=head[from];
	head[from]=tot;
	return;
}

void Tarjan(int x)
{
	low[x]=dfn[x]=++num;
	sta.push(x);
	for(int i=head[x];i;i=edge[i].next)
	{
		int to=edge[i].to;
		if(dfn[to]==0)
		{
			Tarjan(to);
			low[x]=min(low[x],low[to]);
		}
		else if(color[to]==0)
			low[x]=min(low[x],dfn[to]);
	}
	if(dfn[x]==low[x])
	{
		do
		{
			cnt++;
			color[sta.top()]=cnt;
			sum[cnt]+=value[sta.top()];
			sta.pop();
		}while(sta.top()!=x);
	}
	return;
}

void DFS(int x)
{
	if(f[x]!=0) return ;
    f[x]=sum[x];
    int maxn=0;
    for(int i=head[x];i;i=edge[i].next)
	{
		int y=edge[i].to;
        if(!f[y]) DFS(y);
        maxn=max(maxn,f[y]);
    }
    f[x]+=maxn;
    return;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&value[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&from[i],&to[i]);
		add(from[i],to[i]);
	}

	for(int i=1;i<=n;i++)
		if(dfn[i]==0) Tarjan(i);
	
	memset(edge,0,sizeof(edge));
	memset(head,0,sizeof(head));
	tot=0;
	for(int i=1;i<=m;i++)
		if(color[from[i]]!=color[to[i]])
			add(color[from[i]],color[to[i]]);
			
	for(int i=1;i<=tot;i++)
	{
		if(f[i]==0) DFS(i);
		ans=max(ans,f[i]);
	}
	
	printf("%d\n",ans);
	
	return 0;
}

全部 RE\color{purple}\bf\texttt{RE} 了,怎么回事?

2022/5/10 22:19
加载中...