QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175444#5437. Graph CompletingqzzyqWA 2ms7956kbC++142.8kb2023-09-10 18:12:052023-09-10 18:12:05

Judging History

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

  • [2023-09-10 18:12:05]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7956kb
  • [2023-09-10 18:12:05]
  • 提交

answer

#include<bits/stdc++.h>
#define ll 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(ll x,int y=mod-2) {
	ll 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*4];
unsigned 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],1ll*f[x][i]*f[y][j]%mod);
				add(g[i],mod-1ll*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]=1ll*pw[i-1]*2%mod;
	dfs(1,0);
	for (i=1;i<=n;i++) add(ans,1ll*f[1][i]*pw[i*(i-1)/2]%mod);
	printf("%d",1ll*ans*power(pw[m])%mod);
	return 0;
}

詳細信息

Test #1:

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

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 7956kb

input:

4 4
1 2
2 3
3 4
4 1

output:

998244339

result:

wrong answer 1st numbers differ - expected: '4', found: '998244339'