社区讨论

90pts WA on #21,hack 不过,悬棺求条

P4306[JSOI2010] 连通数参与者 1已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m3obv2xo
此快照首次捕获于
2024/11/19 18:44
去年
此快照最后确认于
2025/11/04 14:24
4 个月前
查看原帖
rt ,record
求一组 hack 即可(
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2005;
int n;
vector<int>g[N],G[N];
int rd()
{
	char c=getchar();
	while(c!='0' and c!='1')c=getchar();
	return c-'0';
}
int stk[N],tp;
bool instk[N];
int scc[N],siz[N],num;
int dfn[N],low[N],inx;
int u[N];
queue<int>q;
void tar(int x)
{
	if(dfn[x])return;
	stk[++tp]=x;
	instk[x]=1;
	dfn[x]=low[x]=++inx;
	for(auto y:g[x])
	{
		if(!dfn[y])
		{
			tar(y);
			low[x]=min(low[x],low[y]);
		}
		else if(instk[y])low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x])
	{
		int p;
		num++;
		do{
			p=stk[tp--];
			instk[p]=0;
			siz[num]++;
			scc[p]=num;
		}while(x!=p);
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(rd())
				if(i!=j)g[i].push_back(j);
	for(int i=1;i<=n;i++)tar(i);
	for(int x=1;x<=n;x++)
	{
		for(auto y:g[x])
		{
			if(scc[x]!=scc[y])
			{
				G[scc[y]].push_back(scc[x]);
				u[scc[x]]++;
			}
		}
	}
	for(int i=1;i<=num;i++)
	{
		if(u[i]==0)
			q.push(i);
	}
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(auto y:G[x])
		{
			siz[y]+=siz[x];
			u[y]--;
			if(u[y]==0)q.push(y);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans+=siz[scc[i]];
	cout<<ans;
}
/*

4
0110
1000
0001
0010

*/

回复

2 条回复,欢迎继续交流。

正在加载回复...