QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#173383#5437. Graph CompletingdsakhdkasWA 2ms4012kbC++141.8kb2023-09-09 23:24:312023-09-09 23:24:32

Judging History

你现在查看的是最新测评结果

  • [2023-09-09 23:24:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4012kb
  • [2023-09-09 23:24:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int Mod=998244353;
int t=1,n,m,sum[5010],dfn[5010],low[5010],sta[5010],top,f[5010][5010],col[5010],cnt,tot,Link[5010],tmpf[5010];
int p[25000010],s[5010],ss[5010];
vector <int> V[5010];
bool fla[20010];
struct edge
{
	int v,nex;
}e[20010];
void Add_edge(int x,int y) 
{
	e[++t].nex=Link[x];e[t].v=y;Link[x]=t;
	return;
}
void Tarjan(int now,int las)
{
	dfn[now]=low[now]=++tot;sta[++top]=now;
	for (int i=Link[now];i;i=e[i].nex)
	  if (!dfn[e[i].v]) {
	  	  Tarjan(e[i].v,i);
	  	  low[now]=min(low[now],low[e[i].v]);
	  	  if (low[e[i].v]>dfn[now]) fla[i]=fla[i^1]=true;
	  }
	  else if ((i^1)!=las) low[now]=min(low[now],dfn[e[i].v]);
	if (dfn[now]==low[now]) {
		++cnt;
		int y;
		do {
			y=sta[top--];
			col[y]=cnt;
			s[cnt]++;
		}while (y!=now);
	}
	return ;
}
void dfs(int now,int fa)
{
	f[now][1]=p[s[now]*(s[now]-1)/2-ss[now]/2];sum[now]=1;
	for (int i=0;i<(int)V[now].size();i++) {
		int x=V[now][i];
		if (x==fa) continue;
		dfs(x,now);
		for (int j=1;j<=sum[now]+sum[x];j++) tmpf[j]=0;
		for (int j=1;j<=sum[now];j++) 
		  for (int k=1;k<=sum[x];k++) {
		  	  tmpf[j]+=1LL*f[now][j]*f[x][k]%Mod;tmpf[j]%=Mod;
		  	  tmpf[j+k]-=1LL*f[now][j]*f[x][k]%Mod*p[j*k-1]%Mod;tmpf[j+k]=(tmpf[j+k]+Mod)%Mod;
		  }
		sum[now]+=sum[x];
		for (int j=1;j<=sum[now];j++)
		  f[now][j]=tmpf[j];
	}
	return ;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		Add_edge(x,y);Add_edge(y,x);
	}
	Tarjan(1,0);
	for (int i=1;i<=n;i++)
	  for (int j=Link[i];j;j=e[j].nex)
	    if (fla[j])
	      V[col[i]].push_back(col[e[j].v]);
	    else ss[col[i]]++;
	p[0]=1;
	for (int i=1;i<=n*n;i++)
	  p[i]=(p[i-1]+p[i-1])%Mod;
	dfs(1,0);
	int ans=0;
	for (int i=1;i<=cnt;i++)
	  ans=(ans+f[1][i])%Mod;
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4012kb

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3968kb

input:

4 4
1 2
2 3
3 4
4 1

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 4004kb

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

3 3
1 2
2 3
3 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3964kb

input:

4 3
1 2
2 3
3 4

output:

998244348

result:

wrong answer 1st numbers differ - expected: '5', found: '998244348'