QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152283#5437. Graph CompletingTadijaSebezRE 2ms8040kbC++142.8kb2023-08-27 23:01:432023-08-27 23:01:44

Judging History

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

  • [2023-08-27 23:01:44]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:8040kb
  • [2023-08-27 23:01:43]
  • 提交

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[N],V[N];
int n,m;

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

int disc[N],low[N],tid;
bool bridge[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]]);
		}
	}
}

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

int Solve(){
	DFS(1,0);
	int ans=0;
	for(int i=1;i<=sub[1];i++){
		ckadd(ans,subtract(dp[1][i][0],dp[1][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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7900kb

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 5836kb

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

3 3
1 2
2 3
3 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 3
1 2
2 3
3 4

output:

5

result:

ok 1 number(s): "5"

Test #6:

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

input:

4 3
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #7:

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

input:

4 5
1 2
2 3
3 4
4 1
1 3

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

4 6
1 2
2 3
3 4
4 1
1 3
2 4

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: -100
Runtime Error

input:

141 9870
124 111
31 87
121 106
127 90
54 125
38 17
115 23
129 111
8 116
90 85
10 29
96 110
24 125
51 113
119 33
58 64
8 5
54 97
112 44
70 138
116 85
38 138
138 21
26 18
69 128
68 31
69 42
126 110
49 118
83 124
69 4
9 110
88 104
48 53
46 30
111 120
99 85
13 85
73 85
40 124
39 38
121 40
46 100
29 61
4...

output:


result: