QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486019 | #5437. Graph Completing | Wangzehao2009 | RE | 0ms | 0kb | C++14 | 1.9kb | 2024-07-21 14:32:32 | 2024-07-21 14:32:33 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=998244353;
int n,m,tot=0,dfn[5005],low[5005],cnt=0,id[5005],sz[5005],dp[5005][5005],edge[5005],pw[25000005];
vector<int> G[5005],nG[5005],H[5005];
stack<int> st;
void tarjan(int x,int f){
dfn[x]=low[x]=++tot;
st.push(x);
for(auto y:G[x]){
if(y==f) continue;
if(!dfn[y]){
tarjan(y,x);
low[x]=min(low[x],low[y]);
if(low[y]==dfn[y]) nG[x].push_back(id[y]);
}
else low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x]){
cnt++;
while(st.top()!=x){
id[st.top()]=cnt;
sz[cnt]++;
for(auto t:nG[st.top()]) H[cnt].push_back(t),H[t].push_back(cnt);
st.pop();
}
id[x]=cnt;
sz[cnt]++;
for(auto t:nG[x]) H[cnt].push_back(t),H[t].push_back(cnt);
st.pop();
}
}
void dfs(int x,int f){
dp[x][1]=pw[sz[x]*(sz[x]-1)/2-edge[id[x]]];
for(auto y:H[x]){
if(y==f) continue;
dfs(y,x);
for(int i=sz[x];i>=1;i--){
int t=dp[x][i];
dp[x][i]=0;
for(int j=1;j<=sz[y];j++){
dp[x][i+j]=(dp[x][i+j]+1ll*t*dp[y][j]%MOD*pw[i*j-1]%MOD)%MOD;
dp[x][i]=(dp[x][i]-1ll*t*dp[y][j]%MOD+MOD)%MOD;
}
}
sz[x]+=sz[y];
}
}
signed main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
tarjan(1,0);
for(int i=1;i<=n;i++){
for(auto j:G[i]) if(id[i]==id[j]&&i>j) edge[id[i]]++;
}
pw[0]=1;
for(int i=1;i<=n*n;i++) pw[i]=2*pw[i-1]%MOD;
dfs(1,0);
int ans=0;
for(int i=1;i<=n;i++) ans=(ans+dp[1][i])%MOD;
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 1 2 2 3