QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152285#5437. Graph CompletingTadijaSebezWA 1ms6132kbC++142.9kb2023-08-27 23:08:452023-08-27 23:08:46

Judging History

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

  • [2023-08-27 23:08:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6132kb
  • [2023-08-27 23:08:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int mod=998244353;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int subtract(int x,int y){x-=y;return x<0?x+mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
int powmod(int x,int k){
	int ans=1;
	for(;k;k>>=1,x=mul(x,x)){
		if(k&1)ans=mul(ans,x);
	}
	return ans;
}
void ckadd(int&x,int y){x=add(x,y);}

const int N=5050;
int po2[N*N];

vector<pair<int,int>> G[N];
vector<int> T[N];
int U[2*N],V[2*N];
int n,m;

vector<int> E[N];
int sz[N],edgs[N],csz,sub[N];

int disc[N],low[N],tid;
bool bridge[2*N];
void Bridges(int u,int p){
	disc[u]=low[u]=++tid;
	for(auto e:G[u]){
		if(e.first==p)continue;
		if(!disc[e.first]){
			Bridges(e.first,u);
			if(low[e.first]==disc[e.first]){
				bridge[e.second]=true;
			}
			low[u]=min(low[u],low[e.first]);
		}else{
			low[u]=min(low[u],disc[e.first]);
		}
	}
}
bool was[N];
int nodeCnt,edgeCnt;
int where[N];
void CNT(int u,int chn){
	was[u]=true;
	where[u]=chn;
	edgeCnt+=T[u].size();
	nodeCnt++;
	for(int v:T[u]){
		if(!was[v]){
			CNT(v,chn);
		}
	}
}
void Compress(){
	Bridges(1,0);
	for(int i=1;i<=m;i++){
		if(!bridge[i]){
			T[U[i]].pb(V[i]);
			T[V[i]].pb(U[i]);
		}
	}
	for(int i=1;i<=n;i++){
		if(!was[i]){
			csz++;
			nodeCnt=0;
			edgeCnt=0;
			CNT(i,csz);
			edgeCnt/=2;
			sz[csz]=nodeCnt;
			edgs[csz]=edgeCnt;
		}
	}
	for(int i=1;i<=m;i++){
		if(bridge[i]){
			E[where[U[i]]].pb(where[V[i]]);
			E[where[V[i]]].pb(where[U[i]]);
		}
	}
}

vector<array<int,2>> DFS(int u,int p){
	vector<array<int,2>> dp(sz[u]+1,{0,0});
	dp[sz[u]][0]=po2[sz[u]*(sz[u]-1)/2-edgs[u]];
	sub[u]=sz[u];
	for(int v:E[u]){
		if(v!=p){
			vector<array<int,2>> dpv=DFS(v,u);
			vector<array<int,2>> tmp(sub[u]+sub[v]+1,{0,0});
			for(int i=sub[u]+sub[v];i>=1;i--){
				for(int j=1;j<=sub[v];j++){
					if(i>=j){
						ckadd(tmp[i][0],mul(dp[i-j][0],mul(dpv[j][0],po2[(i-j)*j-1])));
						ckadd(tmp[i][0],mul(dp[i-j][1],mul(dpv[j][1],po2[(i-j)*j-1])));
					}
					ckadd(tmp[i][0],mul(dp[i][0],dpv[j][1]));
					ckadd(tmp[i][0],mul(dp[i][1],dpv[j][0]));
					if(i>=j){
						ckadd(tmp[i][1],mul(dp[i-j][0],mul(dpv[j][1],po2[(i-j)*j-1])));
						ckadd(tmp[i][1],mul(dp[i-j][1],mul(dpv[j][0],po2[(i-j)*j-1])));
					}
					ckadd(tmp[i][1],mul(dp[i][0],dpv[j][0]));
					ckadd(tmp[i][1],mul(dp[i][1],dpv[j][1]));
				}
			}
			sub[u]+=sub[v];
			dp=tmp;
		}
	}
	return dp;
}

int Solve(){
	auto dp=DFS(1,0);
	int ans=0;
	for(int i=1;i<=sub[1];i++){
		ckadd(ans,subtract(dp[i][0],dp[i][1]));
	}
	return ans;
}
int main(){
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%i %i",&U[i],&V[i]);
		G[U[i]].pb({V[i],i});
		G[V[i]].pb({U[i],i});
	}
	po2[0]=1;
	for(int i=1;i<=n*n;i++){
		po2[i]=mul(po2[i-1],2);
	}
	Compress();
	printf("%i\n",Solve());
	return 0;
}

详细

Test #1:

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

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 1ms
memory: 4436kb

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

3 3
1 2
2 3
3 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 4164kb

input:

4 3
1 2
2 3
3 4

output:

32367041

result:

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