QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227144 | #5437. Graph Completing | ucup-team870 | WA | 1ms | 6028kb | C++20 | 2.5kb | 2023-10-26 23:36:25 | 2023-10-26 23:36:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,l,r) for(int i=(l); i<=(r); i++)
#define per(i,r,l) for(int i=(r); i>=(l); i--)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
const int N=5005,mod=998244353;
ll dp[N][N],py[N],pc2[N];
bool eg[N][N];
vi tu1[N],tu[N];
int dfn[N],low[N],cnt,sta[N],vis[N],top;
int bel[N],sz[N],id[N];
inline void add(ll &x,ll y){x=(x+y)%mod;}
ll qp(ll x,ll y){
ll res=1;
while(y){
if(y&1)res=res*x%mod;
x=x*x%mod; y>>=1;
} return res;
}
void tarjan(int now,int pre){
dfn[now]=low[now]=++cnt;
sta[++top]=now; vis[now]=1;
for(int son:tu1[now]){
if(son==pre)continue;
if(!dfn[son]){
tarjan(son,now);
low[now]=min(low[now],low[son]);
}
else if(vis[son]){
low[now]=min(low[now],low[son]);
}
}
if(low[now]==dfn[now]){
while(sta[top+1] != now){
bel[sta[top]]=now;
vis[sta[top]]=0; --top;
}
}
}
ll calsum(int now,int sz){
ll sum=0;
rep(i,1,sz){
// cout<<now<<' '<<dp[now][i]<<' '<<pc2[i]<<endl;
add(sum,dp[now][i]*pc2[i]);
}
return (mod-sum)%mod;
}
void dfs(int now,int pre){
dp[now][sz[now]]=mod-1;
for(int son:tu[now]){
if(son==pre)continue;
dfs(son,now);
ll sum=calsum(son,sz[son]);
rep(i,1,sz[now]+sz[son])py[i]=0;
rep(i,1,sz[now])py[i]=dp[now][i]*sum%mod;
rep(i,1,sz[now]){
rep(j,1,sz[son])add(py[i+j], dp[now][i]*dp[son][j]);
}
sz[now]+=sz[son];
rep(i,1,sz[now])dp[now][i]=py[i];
}
}
signed main(){
IOS
int n,Q;cin>>n>>Q;
rep(i,1,n)pc2[i]=qp(2,i*(i-1)/2+1);
rep(_,1,Q){
int u,v;cin>>u>>v;
tu1[u].push_back(v); tu1[v].push_back(u);
}
tarjan(1,0);
int m=0;
rep(i,1,n){
// cout<<bel[i]<<' ';
if(bel[i]==i)id[i]=++m;
}
// cout<<endl;
rep(i,1,n){
bel[i]=id[bel[i]];
++sz[bel[i]];
// cout<<bel[i]<<' ';
}
// cout<<endl;
auto addeg=[&](int u,int v){
if(u==v)return;
if(!eg[u][v]){
tu[u].push_back(v); eg[u][v]=1;
}
};
rep(i,1,n){
for(auto v:tu1[i])addeg(bel[i],bel[v]);
}
// cout<<m<<' '<<sz[1]<<endl;
dfs(1,0);
ll ans=calsum(1,sz[1]);
ans=ans*qp(qp(2,Q+1),mod-2)%mod;
cout<<ans<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5972kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5932kb
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: 1ms
memory: 6028kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
3 3 1 2 2 3 3 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5972kb
input:
4 3 1 2 2 3 3 4
output:
998244348
result:
wrong answer 1st numbers differ - expected: '5', found: '998244348'