QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175125 | #5437. Graph Completing | qzzyq | RE | 2ms | 7888kb | C++14 | 2.9kb | 2023-09-10 16:15:47 | 2023-09-10 16:15:47 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define maxn 5005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
void read(int &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=998244353;
int power(int x,int y=mod-2) {
int sum=1;
while (y) {
if (y&1) sum=sum*x%mod;
x=x*x%mod;y>>=1;
}
return sum;
}
int h[maxn],head=1;
struct yyy {
int to,z,flag;
void add(int x,int y) {
to=y;z=h[x];h[x]=head;
}
}a[maxn*2];
int pw[maxn*maxn];
vector<int>to[maxn];
int times,tot,n,m,eccnum;
int dfn[maxn],low[maxn],stac[maxn],vis[maxn],ecc[maxn];
void tarjan(int x,int pre) {
int i;
dfn[x]=low[x]=++times;stac[++tot]=x;vis[x]=1;
for (i=h[x];i;i=a[i].z) if ((i^1)^pre) {
if (!dfn[a[i].to]) {
tarjan(a[i].to,i);
low[x]=min(low[x],low[a[i].to]);
if (dfn[x]<low[a[i].to]) {
a[i].flag=a[i^1].flag=1;
++eccnum;
while (tot) {
if (stac[tot]==x) break;
ecc[stac[tot]]=eccnum;
vis[stac[tot]]=0;
tot--;
}
}
}
else if (vis[a[i].to]) low[x]=min(low[x],dfn[a[i].to]);
}
}
int f[maxn][maxn],g[maxn],siz[maxn];
void add(int &x,int y) {x=(x+y)%mod;}
void dfs(int x,int pre) {
int i,j;
f[x][siz[x]]=1;
for (auto y:to[x]) if (y^pre) {
dfs(y,x);
for (i=1;i<=siz[x];i++) {
for (j=1;j<=siz[y];j++){
add(g[i+j],f[x][i]*f[y][j]);
add(g[i],mod-f[x][i]*f[y][j]%mod*pw[j*(j-1)/2]*2%mod);
}
}
siz[x]+=siz[y];
for (i=0;i<=siz[x];i++) f[x][i]=g[i],g[i]=0;
}
}
int ans;
signed main(void){
int i,j,x,y;
read(n);read(m);
for (i=1;i<=m;i++) {
read(x);read(y);
a[++head].add(x,y);
a[++head].add(y,x);
}
for (i=1;i<=n;i++) if (!dfn[i]) {
tarjan(i,0);
if (tot) {
++eccnum;
while (tot) {
ecc[stac[tot]]=eccnum;
vis[stac[tot]]=0;
tot--;
}
}
}
for (i=1;i<=n;i++) {
siz[ecc[i]]++;
for (j=h[i];j;j=a[j].z)
if (ecc[i]^ecc[a[j].to]) {
to[ecc[i]].push_back(ecc[a[j].to]);
// gdb(ecc[i],ecc[a[j].to]);
}
}
int N=n*n;
for (pw[0]=1,i=1;i<=N;i++) pw[i]=pw[i-1]*2%mod;
dfs(1,0);
// for (i=1;i<=n;i++) gdb(i,f[1][i]);
for (i=1;i<=n;i++) add(ans,f[1][i]*pw[i*(i-1)/2]%mod);
// gdb(f[1][4],pw[6],pw[m],ans);
printf("%lld",ans*power(pw[m])%mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7688kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5548kb
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: 5624kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7888kb
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: 5864kb
input:
4 3 1 2 2 3 3 4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7732kb
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: 5596kb
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: 5844kb
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: -100
Runtime Error
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...