QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#148813 | #5437. Graph Completing | 11d10xy | WA | 1ms | 4352kb | C++14 | 1.7kb | 2023-08-23 19:09:44 | 2023-08-23 20:29:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=9998244353,i2=mod+1>>1;
struct qpow{
ll pp1[5010],pp2[5010];
qpow(ll p){
pp1[0]=1;for(int i=1;i<=5000;i++)pp1[i]=pp1[i-1]*p%mod;
p=pp1[5000];
pp2[0]=1;for(int i=1;i<=5000;i++)pp2[i]=pp2[i-1]*p%mod;
}ll operator()(ll t){return pp1[t%5000]*pp2[t/5000]%mod;}
}p2(2);
ll dp[5010][5010];
int n,m,dfn[5010],low[5010],stk[5010],bl[5010],sz[5010],vc[5010],ec[5010],tp,tot,edcc=0;
set<int>G[5010],adj[5010];
void tarjan(int u,int fa){
dfn[u]=low[u]=++tot;
stk[++tp]=u;
for(int v:G[u])
if(!dfn[v])tarjan(v,u),low[u]=min(low[u],low[v]);
else if(v!=fa)low[u]=min(low[u],dfn[v]);
if(dfn[u]==low[u]){
edcc++;int v;
do{
v=stk[tp--],vc[edcc]++,bl[v]=edcc;
for(int x:G[v])if(bl[x])
if(bl[x]!=edcc)adj[edcc].insert(bl[x]);
else ec[edcc]++;
}while(v!=u);
}
}
void solve(int u){
static int t[5010];
dp[u][0]=p2(vc[u]*1ll*(vc[u]-1)/2-ec[u]);
for(int v:adj[u]){
solve(v);
for(int i=0;i<=sz[u];i++)t[i]=dp[u][i],dp[u][i]=0;
for(int i=0;i<=sz[u];i++)
for(int j=0;j<=sz[v];j++)
(dp[u][i+j]+=t[i]*dp[v][j]%mod*p2(i*1ll*j-1)%mod)%=mod,
(dp[u][i]+=t[i]*dp[v][j]%mod*(mod-1))%=mod;
sz[u]+=sz[v];
}sz[u]+=vc[u];
for(int i=sz[u];i>=0;i--)
dp[u][i]=i<vc[u]?0:dp[u][i-vc[u]];
}
int main(){
cin>>n>>m;
for(int i=1,u,v;i<=m;i++)
scanf("%d%d",&u,&v),G[u].insert(v),G[v].insert(u);
tarjan(1,0),solve(1);
ll ans=0;
for(int i=0;i<=n;i++)ans+=dp[1][i];
cout<<ans%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4188kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4352kb
input:
4 4 1 2 2 3 3 4 4 1
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4112kb
input:
2 1 1 2
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'