QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155110#5437. Graph Completing275307894aWA 2ms8308kbC++142.0kb2023-09-01 11:06:572023-09-01 11:06:58

Judging History

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

  • [2023-09-01 11:06:58]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8308kb
  • [2023-09-01 11:06:57]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=5e3+5,M=N*N+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,m,X[N],Y[N];ll Po[M/2];vector<int> S[N];
int scc[N],CC;
void con(int x,int y){S[x].emplace_back(y);S[y].emplace_back(x);}
namespace Tarjan{
	int dfn[N],low[N],dh,st[N],sh;
	void Tarjan(int x,int La){
		dfn[x]=low[x]=++dh;st[++sh]=x;
		for(int i:S[x]) if(i^La) {
			if(dfn[i]) low[x]=min(low[x],dfn[i]);
			else Tarjan(i,x),low[x]=min(low[x],low[i]);
		}
		if(low[x]==dfn[x]){++CC;while(st[sh+1]^x) scc[st[sh]]=CC,sh--;}
	}
	void BD(){for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i,0);}
}
int w[N],siz[N];ll dp[N][N],g[N];
void dfs(int x,int La){
	dp[x][siz[x]]=Po[siz[x]*(siz[x]-1)/2-w[x]];
	for(int i:S[x]) if(i^La){
		dfs(i,x);
		Mc(g,dp[x]);Me(dp[x],0);
		for(int j=1;j<=siz[x];j++){
			for(int h=0;h<=siz[i];h++) dp[x][j+h]=(dp[x][j+h]+g[j]*dp[i][h]%mod*Po[max(j*h-1,0)])%mod;
		}
		siz[x]+=siz[i];
	}
	for(int i=1;i<=siz[x];i++) dp[x][0]=(dp[x][0]+mod-dp[x][i])%mod;
	// for(int i=0;i<=siz[x];i++) cerr<<dp[x][i]<<' ';cerr<<'\n';
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	for(Po[0]=i=1;i<=n*(n-1)/2;i++) Po[i]=Po[i-1]*2%mod;
	for(i=1;i<=m;i++) scanf("%d%d",&X[i],&Y[i]),con(X[i],Y[i]);
	Tarjan::BD();
	for(i=1;i<=n;i++) S[i].clear();
	for(i=1;i<=n;i++) siz[scc[i]]++;
	for(i=1;i<=m;i++) if(scc[X[i]]==scc[Y[i]]) w[scc[X[i]]]++;else con(scc[X[i]],scc[Y[i]]);
	dfs(1,0);
	printf("%lld\n",(mod-dp[1][0])%mod);
}
int main(){
	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

3 3
1 2
2 3
3 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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

input:

4 3
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #7:

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

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: 0ms
memory: 6112kb

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
Wrong Answer
time: 2ms
memory: 6224kb

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:

753269315

result:

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