QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668218 | #5437. Graph Completing | ocharin | WA | 0ms | 3624kb | C++20 | 2.9kb | 2024-10-23 12:38:34 | 2024-10-23 12:38:35 |
Judging History
answer
/*
_/ _/
_/_/ _/_/_/ _/_/_/ _/_/_/ _/ _/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/ _/_/_/ _/ _/ _/_/_/ _/ _/ _/ _/
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
void solve(){
int n,m;
cin>>n>>m;
vector<int>p(n+1),pp(n+1);
auto cal=[&](int x)->int{
return p[x%n]*pp[x/n]%mod;
};
p[0]=pp[0]=1;
for(int i=1;i<=n;++i) p[i]=p[i-1]*2%mod;
for(int i=1;i<=n;++i) pp[i]=pp[i]*p[n]%mod;
vector<int>head(n,-1),to(2*m),nxt(2*m,-1);
int cnt=-1;
auto add=[&](int u,int v)->void{
to[++cnt]=v;
nxt[cnt]=head[u];
head[u]=cnt;
};
for(int i=0;i<m;++i){
int u,v;
cin>>u>>v;
--u,--v;
add(u,v);
add(v,u);
}
vector<int>dfn(n),low(n);
int idx=0;
stack<int>st;
vector<int>id(n);
auto tarjan=[&](auto tarjan,int u,int in)->void{
dfn[u]=low[u]=++cnt;
st.push(u);
for(int i=head[u];~i;i=nxt[i]){
int v=to[i];
if(!dfn[v]){
tarjan(tarjan,v,i^1);
low[u]=min(low[u],low[v]);
}
else if(i!=in) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
int x=st.top();st.pop();
id[x]=idx;
while(x!=u){
x=st.top();st.pop();
id[x]=idx;
}
idx++;
}
};
tarjan(tarjan,0,-1);
vector<int>sz(idx),c(idx);
vector<vector<int>>e(idx);
for(int i=0;i<n;++i){
int u=id[i];
sz[u]++;
for(int j=head[i];~j;j=nxt[j]){
int v=id[to[j]];
if(u!=v) e[u].push_back(v);
else c[u]++;
}
}
vector f(idx,vector(n+1,0ll));
auto dfs=[&](auto dfs,int u,int fa)->void{
f[u][sz[u]]=cal((sz[u]-1)*sz[u]/2-c[u]/2);
for(auto v:e[u]){
if(v==fa) continue;
dfs(dfs,v,u);
vector<int>g(sz[u]+sz[v]+1,0ll);
for(int i=0;i<=sz[u];++i){
for(int j=0;j<=sz[v];++j){
g[i+j]+=f[u][i]*f[v][j]%mod*cal(i*j-1)%mod;
if(g[i+j]>=mod) g[i+j]-=mod;
g[i]+=mod-f[u][i]*f[v][j]%mod;
if(g[i]>=mod) g[i]-=mod;
}
}
}
};
dfs(dfs,0,-1);
int res=0;
for(int i=0;i<=n;++i){
res+=f[0][i];
if(res>=mod) res-=mod;
}
cout<<res<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
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: 0ms
memory: 3624kb
input:
2 1 1 2
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'