QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630748 | #5437. Graph Completing | jaker | TL | 1ms | 6148kb | C++14 | 2.3kb | 2024-10-11 20:15:38 | 2024-10-11 20:15:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=5050;
const int mod=998244353;
int n,m,u[maxn<<1],v[maxn<<1],pre[maxn<<1],now[maxn],son[maxn<<1],tot=1;
int dfn[maxn],low[maxn],ok[maxn<<1],scc[maxn];
int cnt[maxn],siz[maxn],pw2[maxn],tmp[maxn];
int f[maxn][maxn];
vector<int> G[maxn];
int power(int x,long long y)
{
y%=(mod-1);
int ans=1;
while(y)
{
if(y&1)
ans=1ll*ans*x%mod;
y>>=1;
x=1ll*x*x%mod;
}
return ans;
}
void put(int x,int y)
{
pre[++tot]=now[x];
now[x]=tot;
son[tot]=y;
}
void tarjan(int x,int fa)
{
dfn[x]=low[x]=++dfn[0];
for(int p=now[x];p;p=pre[p])
{
int t=son[p];
if(t==fa)
continue;
if(!dfn[t])
{
tarjan(t,x);
low[x]=min(low[x],low[t]);
if(low[t]>dfn[x])
ok[p]=ok[p^1]=1;
}
else
low[x]=min(low[x],dfn[t]);
}
}
void dfs1(int x,int id)
{
scc[x]=id;cnt[id]++;
for(int p=now[x];p;p=pre[p])
{
int t=son[p];
if(!scc[t]&&!ok[p])
dfs1(t,id);
}
}
void dfs2(int x,int fa)
{
siz[x]=cnt[x];
f[x][cnt[x]]=1;
for(int t:G[x])
if(t!=fa)
{
dfs2(t,x);
for(int i=0;i<=siz[x]+siz[t];i++)
tmp[i]=0;
for(int i=1;i<=siz[x];i++)
for(int j=1;j<=siz[t];j++)
tmp[i+j]=(tmp[i+j]+1ll*f[x][i]*f[t][j])%mod,tmp[i]=(tmp[i]-1ll*pw2[j]*f[x][i]%mod*f[t][j]%mod+mod)%mod;
siz[x]+=siz[t];
for(int i=1;i<=siz[x];i++)
f[x][i]=tmp[i];
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
pw2[i]=power(2,1ll*i*(i-1)/2-(i-1));
for(int i=1;i<=m;i++)
scanf("%d%d",&u[i],&v[i]),put(u[i],v[i]),put(v[i],u[i]);
tarjan(1,0);
for(int i=1;i<=n;i++)
if(!scc[i])
dfs1(i,++scc[0]);
for(int i=1;i<=m;i++)
if(scc[u[i]]!=scc[v[i]])
G[scc[u[i]]].push_back(scc[v[i]]),G[scc[v[i]]].push_back(scc[u[i]]);
dfs2(1,0);
int ans=0;
for(int i=1;i<=n;i++)
ans=(ans+1ll*f[1][i]*pw2[i])%mod;
printf("%lld\n",1ll*ans*power(2,1ll*(mod-2)*(m-n+1))%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4004kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4116kb
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: 4088kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4052kb
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: 6148kb
input:
4 3 1 2 2 3 3 4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 4076kb
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: 3972kb
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: 5920kb
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
Time Limit Exceeded
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...