QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#767636 | #5437. Graph Completing | weiqianping | WA | 0ms | 4000kb | C++14 | 1.0kb | 2024-11-20 21:32:35 | 2024-11-20 21:32:43 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;
int n,m,low[N],dfn,mod=998244353;
vector<int> G[N];
void dfs(int u,int fa)
{
low[u]=++dfn;
for(int i=0;i<G[u].size(); i++)
{
int v=G[u][i];
if(v==fa) continue;
if(!low[v]) dfs(v,u);
low[u]=min(low[u],low[v]);
}
}
int tarjan()
{
int degree[N];
memset(degree,0,sizeof(degree));
for(int i=1;i<=n;i++)
{
for(int j=0;j<G[i].size();j++)
{
if(low[i]!=low[G[i][j]]) degree[low[i]]++;
}
}
int res=0;
for(int i=1;i<=n;i++)
{
if(degree[i]==1) res++;
}
return res;
}
int qpow(int a,int b)
{
int res=1;
while(b>0)
{
if(b%2) res=(res*a)%mod;
a=(a*a)%mod;
b/=2;
}
return res;
}
signed main()
{
scanf("%lld %lld",&n,&m);
for(int i=1;i<=m;++i)
{
int a,b;
scanf("%lld %lld",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
dfn=0;
dfs(1,-1);
int x=tarjan();
// printf("%lld", x);
x=(x+1)/2;
// printf("%lld\n",x);
printf("%lld",qpow(2,n*(n-1)/2-m-x));
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4000kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3940kb
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: 3996kb
input:
2 1 1 2
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'