QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#285940#5437. Graph Completingushg8877WA 1ms3932kbC++141.5kb2023-12-17 00:33:032023-12-17 00:33:03

Judging History

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

  • [2023-12-17 00:33:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3932kb
  • [2023-12-17 00:33:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=5005;
const int MOD=998244353;
int n,m,np,scc[MAXN],siz[MAXN],in[MAXN];
int low[MAXN],dfn[MAXN],tot,st[MAXN],top;
ll f[MAXN][MAXN],g[MAXN];
vector<int> edg[MAXN],tre[MAXN];
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;} 
void tarjan(int u,int fa){
	st[++top]=u;low[u]=dfn[u]=++tot;
	for(int v:edg[u]) if(v!=fa){
		if(dfn[v]) low[u]=min(low[u],dfn[v]);
		else{
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
		}
	}
	if(low[u]==dfn[u]){
		++np;
		while(st[top+1]!=u){
			scc[st[top--]]=np;
			siz[np]++;
		}
		in[np]=siz[np]*(siz[np]-1)/2; 
	}
}
void dfs(int u,int fa){
	f[u][siz[u]]=ksm(2,in[u]);
	for(int v:tre[u]) if(v!=fa){
		dfs(v,u);
		memset(g,0,sizeof(g));
		for(int i=0;i<=siz[u];i++)
			for(int j=0;j<=siz[v];j++){
				g[i+j]+=f[u][i]*f[v][j]%MOD*ksm(2,i+j)%MOD;
				g[i]+=f[u][i]*f[v][j]%MOD*(MOD-1)%MOD;
			}
		siz[u]+=siz[v];
		for(int i=0;i<=siz[u];i++) g[i]%=MOD;
		swap(g,f[u]);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		edg[u].push_back(v);
		edg[v].push_back(u);
	}
	tarjan(1,0);
	for(int i=1;i<=n;i++) for(int j:edg[i]){
		if(scc[i]!=scc[j]) edg[scc[i]].push_back(scc[j]);
		else if(i<j) in[scc[i]]--;
	}
	dfs(1,0);
	ll ans=0;
	for(int i=1;i<=n;i++) ans+=f[1][i];
	cout<<ans%MOD;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3828kb

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

4 4
1 2
2 3
3 4
4 1

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

2 1
1 2

output:

1

result:

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