QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630739#5437. Graph CompletingjakerTL 1ms6068kbC++142.3kb2024-10-11 20:14:472024-10-11 20:14:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 20:14:47]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:6068kb
  • [2024-10-11 20:14:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5050;
const int mod=998244353;
int n,m,u[maxn],v[maxn],pre[maxn<<1],now[maxn],son[maxn<<1],tot=1;
int dfn[maxn],low[maxn],ok[maxn<<1],scc[maxn];
int cnt[maxn],siz[maxn],pw2[maxn],tmp[maxn];
int f[maxn][maxn];
vector<int> G[maxn];
int power(int x,long long y)
{
    y%=(mod-1);
    int ans=1;
    while(y)
    {
        if(y&1)
            ans=1ll*ans*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return ans;
}
void put(int x,int y)
{
    pre[++tot]=now[x];
    now[x]=tot;
    son[tot]=y;
}
void tarjan(int x,int fa)
{
    dfn[x]=low[x]=++dfn[0];
    for(int p=now[x];p;p=pre[p])
    {
        int t=son[p];
        if(t==fa)
            continue;
        if(!dfn[t])
        {
            tarjan(t,x);
            low[x]=min(low[x],low[t]);
            if(low[t]>dfn[x])
                ok[p]=ok[p^1]=1;
        }
        else
            low[x]=min(low[x],dfn[t]);
    }
}
void dfs1(int x,int id)
{
    scc[x]=id;cnt[id]++;
    for(int p=now[x];p;p=pre[p])
    {
        int t=son[p];
        if(!scc[t]&&!ok[p])
            dfs1(t,id);
    }
}
void dfs2(int x,int fa)
{
    siz[x]=cnt[x];
    f[x][cnt[x]]=1;
    for(int t:G[x])
        if(t!=fa)
        {
            dfs2(t,x);
            for(int i=0;i<=siz[x]+siz[t];i++)
                tmp[i]=0;
            for(int i=1;i<=siz[x];i++)
                for(int j=1;j<=siz[t];j++)
                    tmp[i+j]=(tmp[i+j]+1ll*f[x][i]*f[t][j])%mod,tmp[i]=(tmp[i]-1ll*pw2[j]*f[x][i]%mod*f[t][j]%mod+mod)%mod;
            siz[x]+=siz[t];
            for(int i=1;i<=siz[x];i++)
                f[x][i]=tmp[i];
        }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        pw2[i]=power(2,1ll*i*(i-1)/2-(i-1));
    for(int i=1;i<=m;i++)
        scanf("%d%d",&u[i],&v[i]),put(u[i],v[i]),put(v[i],u[i]);
    tarjan(1,0);
    for(int i=1;i<=n;i++)
        if(!scc[i])
            dfs1(i,++scc[0]);
    for(int i=1;i<=m;i++)
        if(scc[u[i]]!=scc[v[i]])
            G[scc[u[i]]].push_back(scc[v[i]]),G[scc[v[i]]].push_back(scc[u[i]]);
    dfs2(1,0);
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=(ans+1ll*f[1][i]*pw2[i])%mod;
    printf("%lld\n",1ll*ans*power(2,1ll*(mod-2)*(m-n+1))%mod);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3920kb

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6024kb

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: 5956kb

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5956kb

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: 5956kb

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: 4072kb

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: 6068kb

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: 0ms
memory: 4076kb

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
Time Limit Exceeded

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:


result: