QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#271267 | #5437. Graph Completing | ship2077 | WA | 1ms | 6088kb | C++14 | 1.8kb | 2023-12-02 08:51:33 | 2023-12-02 08:51:34 |
Judging History
answer
#include<bits/stdc++.h>
#define reduce(x) (x>=mod?x-mod:x)
using namespace std;
constexpr int M=5e3+5,mod=998244353;
int n,m,x,y,ans,num,Index;vector<int>G[M];
vector<pair<int,int>>g[M];bool vis[M],flag[M<<1];
int tmp[M],bel[M],dfn[M],low[M],siz[M],cnt[M],pw1[M],pw2[M],f[M][M];
int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x*f;
}
int qpow(long long x){return 1ll*pw1[x%n]*pw2[x/n]%mod;}
void dfs1(int x,int f){
dfn[x]=low[x]=++Index;
for (auto [u,v]:g[x]){
if (u==f) continue;
if (!dfn[u]){dfs1(u,x);
low[x]=min(low[x],low[u]);
if (dfn[x]<low[u]) flag[v]=1;
}
else low[x]=min(low[x],dfn[u]);
}
}
void dfs2(int x){
siz[bel[x]=num]++;vis[x]=1;
for (auto [u,v]:g[x])
if (!vis[u]&&!flag[v]) dfs2(u);
}
void dfs3(int x,int fa){
f[x][siz[x]]=qpow(1ll*siz[x]*(siz[x]-1)/2-cnt[x]/2);
for (auto v:G[x]){
if (v==fa) continue;dfs3(v,x);
for (int i=1;i<=siz[x]+siz[v];i++) tmp[i]=0;
for (int i=1;i<=siz[x];i++) if (f[x][i])
for (int j=1;j<=siz[v];j++) if (f[v][j])
tmp[i+j]=(tmp[i+j]+1ll*f[x][i]*f[v][j]%mod*qpow(1ll*i*j-1))%mod,
tmp[i]=reduce(tmp[i]+mod-1ll*f[x][i]*f[v][j]%mod);
siz[x]+=siz[v]; for (int i=1;i<=siz[x];i++) f[x][i]=tmp[i];
}
}
int main(){
n=read();m=read();
for (int i=1;i<=m;i++){
x=read();y=read();
g[x].push_back({y,i});
g[y].push_back({x,i});
} dfs1(1,0);
for (int i=1;i<=n;i++)
if (!vis[i]) ++num,dfs2(i);
for (int i=pw1[0]=1;i<=n;i++) pw1[i]=reduce(pw1[i-1]<<1);
for (int i=pw2[0]=1;i<=n;i++) pw2[i]=1ll*pw2[i-1]*pw1[n]%mod;
for (int i=1;i<=n;i++)
for (auto [j,_]:g[i])
if (bel[i]^bel[j])
G[bel[i]].push_back(bel[j]);
else cnt[bel[i]]++;
dfs3(1,0);
for (int i=1;i<=n;i++)
ans=reduce(ans+f[1][i]);
return printf("%d\n",ans),0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4048kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
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: 4116kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
3 3 1 2 2 3 3 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
4 3 1 2 2 3 3 4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
4 3 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
4 5 1 2 2 3 3 4 4 1 1 3
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
4 6 1 2 2 3 3 4 4 1 1 3 2 4
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 4172kb
input:
141 9870 124 111 31 87 121 106 127 90 54 125 38 17 115 23 129 111 8 116 90 85 10 29 96 110 24 125 51 113 119 33 58 64 8 5 54 97 112 44 70 138 116 85 38 138 138 21 26 18 69 128 68 31 69 42 126 110 49 118 83 124 69 4 9 110 88 104 48 53 46 30 111 120 99 85 13 85 73 85 40 124 39 38 121 40 46 100 29 61 4...
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 4368kb
input:
142 10000 19 3 4 86 36 122 36 88 130 86 107 59 3 119 132 90 80 124 122 95 75 66 70 123 63 119 8 44 114 9 81 19 106 77 96 93 79 141 104 50 117 66 30 48 128 109 56 73 106 116 70 8 72 130 59 110 140 20 40 11 134 71 27 51 33 93 82 96 133 118 50 14 32 64 71 12 48 33 22 32 116 17 104 45 66 71 111 142 131 ...
output:
2048
result:
ok 1 number(s): "2048"
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 6088kb
input:
200 10000 47 42 33 120 146 144 94 170 170 181 20 101 185 190 197 33 18 37 12 86 148 115 136 120 41 182 120 11 44 132 167 67 118 139 114 52 80 37 171 56 93 139 113 112 129 122 166 4 47 60 57 6 104 119 179 104 107 1 8 70 197 70 39 127 134 1 18 26 85 100 158 121 61 105 33 113 51 54 45 85 45 130 97 164 ...
output:
127980855
result:
wrong answer 1st numbers differ - expected: '365281854', found: '127980855'