QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#464514 | #5437. Graph Completing | EthanDong | WA | 88ms | 203344kb | C++14 | 1.6kb | 2024-07-06 10:50:36 | 2024-07-06 10:50:36 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <stack>
#include <cstring>
using namespace std;
const int MOD=998244353;
int clo,dfn[5007],low[5007],vis[5007],tot,sz[5007],cnt[5007];
long long jc[25000007],dp[5007][5007],f[5007];
stack<int> st;
vector<int> g[5007],e[5007];
void tarjan(int u,int fa){
dfn[u]=low[u]=++clo;
st.push(u);
for(int i=0;i<g[u].size();i++){
int v=g[u][i];
if(v==fa) continue;
if(!dfn[v]){
tarjan(v,u);
low[u]=min(low[u],low[v]);
}else low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
tot++;
while(st.top()!=u){
int x=st.top();
st.pop();
sz[tot]++;
vis[x]=tot;
}
int x=st.top();
st.pop();
sz[tot]++;
vis[x]=tot;
}
}
void dfs(int u,int fa){
dp[u][sz[u]]=jc[sz[u]*(sz[u]-1)/2-cnt[u]];
for(int i=0;i<e[u].size();i++){
int v=e[u][i];
if(v==fa) continue;
dfs(v,u);
memset(f,0,sizeof(f));
for(int j=1;j<=sz[u];j++){
for(int k=1;k<=sz[v];k++){
f[j]=(f[j]-dp[u][j]*dp[v][k]%MOD+MOD)%MOD;
(f[j+k]+=(dp[u][j]*dp[v][k]%MOD)*jc[j*k-1]%MOD)%=MOD;
}
dp[u][j]=f[j];
}
sz[u]+=sz[v];
}
}
int x[5007],y[5007],lg[5007][5007];
int main(){
jc[0]=1;
for(int i=1;i<=25000000;i++) jc[i]=jc[i-1]*2%MOD;
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&x[i],&y[i]);
g[x[i]].push_back(y[i]);
g[y[i]].push_back(x[i]);
}
tarjan(1,0);
for(int i=1;i<=m;i++){
int u=x[i],v=y[i];
if(vis[u]==vis[v]) cnt[vis[u]]++;
else{
e[vis[u]].push_back(vis[v]);
e[vis[v]].push_back(vis[u]);
}
}
dfs(1,0);
long long ans=0;
for(int i=1;i<=sz[1];i++) (ans+=dp[1][i])%=MOD;
printf("%lld",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 76ms
memory: 201992kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 88ms
memory: 201520kb
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: 83ms
memory: 203344kb
input:
2 1 1 2
output:
998244352
result:
wrong answer 1st numbers differ - expected: '0', found: '998244352'