QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765360 | #5437. Graph Completing | black_king1 | WA | 88ms | 200680kb | C++17 | 1.8kb | 2024-11-20 14:02:44 | 2024-11-20 14:02:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define M 10005
#define p 998244353
#define ll long long
vector<int> G[N];
ll f[N][N],g[N],mi[N*N],ans=1,sum;
int n,m,dfn[N],low[N],col[N],siz[N],E[N],V[N],cnt,tot;
int head[N],ver[M<<1],nxt[M<<1],cut[M<<1],num=2;
void upd(ll &x,ll y){(x+=y)%=p;}
void add(int u,int v){
ver[num]=v,nxt[num]=head[u],head[u]=num++;
ver[num]=u,nxt[num]=head[v],head[v]=num++;
}
void dfs(int u,int fa){
dfn[u]=low[u]=++tot;
for(int i=head[u];i;i=nxt[i])
if(!dfn[ver[i]]){
dfs(ver[i],u),low[u]=min(low[u],low[ver[i]]);
if(low[ver[i]]>dfn[u])cut[i]=cut[i^1]=1;
}
else if(ver[i]!=fa)low[u]=min(low[u],dfn[ver[i]]);
}
void dfs(int u){
col[u]=cnt;
for(int i=head[u];i;i=nxt[i])
if(!cut[i]){if(!col[ver[i]])dfs(ver[i]);}
else if(col[ver[i]])
G[col[ver[i]]].push_back(col[u]),
G[col[u]].push_back(col[ver[i]]);
}
void dfs2(int u,int fa){
f[u][V[u]]=1;
siz[u]=V[u];
for(int v:G[u])if(v!=fa){
dfs2(v,u);
for(int i=1;i<=siz[u];i++){
for(int j=1;j<=siz[v];j++){
upd(g[i+j],f[u][i]*f[v][j]%p*(mi[i*j-1])-1);
upd(g[i],f[u][i]*f[v][j]%p*(p-1));
}
}
siz[u]+=siz[v];
for(int i=1;i<=siz[u];i++)f[u][i]=g[i],g[i]=0;
}
}
int main(){
mi[0]=1;for(int i=1;i<N*N;i++)mi[i]=mi[i-1]*2%p;
scanf("%d%d",&n,&m);
for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),add(u,v);
dfs(1,0);
for(int i=1;i<=n;i++)if(!col[i])++cnt,dfs(i);
for(int i=1;i<=n;i++)V[col[i]]++;
for(int u=1;u<=n;u++)for(int i=head[u];i;i=nxt[i])
if(u>ver[i]&&col[u]==col[ver[i]])++E[col[u]];
for(int i=1;i<=cnt;i++)ans=ans*mi[(V[i]-1)*V[i]/2-E[i]]%p;
dfs2(1,0);
for(int i=1;i<=n;i++)upd(sum,f[1][i]);
printf("%lld\n",sum*ans%p);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 88ms
memory: 200680kb
input:
3 2 1 2 2 3
output:
998244351
result:
wrong answer 1st numbers differ - expected: '1', found: '998244351'