QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785872#5437. Graph Completingwang_shiWA 1ms6152kbC++143.6kb2024-11-26 19:30:032024-11-26 19:30:04

Judging History

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

  • [2024-11-26 19:30:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6152kb
  • [2024-11-26 19:30:03]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define Nai_Long return 0
#define See_Memory cerr<<abs(&M1-&M2)/1024.0/1024.0<<"MB\n"
#define See_Time cerr<<(clock()-T)*1.0/CLOCKS_PER_SEC<<"s\n"
using namespace std;
const int N=5010,MOD=1e9+7;
bool M1;
mt19937 rng(time(0));
namespace MTool
{
	inline int Cadd(int a,int b){return a+b>=MOD?a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline void Madd(int &a,int b){a=(a+b>=MOD?a+b-MOD:a+b);}
	inline void Mdel(int &a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int &a,int b){a=1ll*a*b%MOD;}
	inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
	inline void Mmod(int &x){x=(x%MOD+MOD)%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args> inline void Madd(int &a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mdel(int &a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline void Mmul(int &a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	int ksm(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x)) if(y&1) Mmul(s,x); return s;}
}
using namespace MTool;
int n,m,dfn[N],low[N],ti,stk[N],top;
int idx,col[N],siz[N],cnt[N];
vector<PII> g[N]; vector<int> e[N];
void Work(int x)
{
	idx++;
	for(int v;v!=x;)
		col[v=stk[top--]]=idx,siz[idx]++;
}
void Tarjan(int u,int pre)
{
	dfn[u]=low[u]=++ti,stk[++top]=u;
	for(PII k:g[u])
	{ 	
		int v=k.fi,id=k.se;
		if(id==pre) continue;
		if(!dfn[v])
		{
			Tarjan(v,id);
			if(low[v]>dfn[u]) Work(v);
			low[u]=min(low[u],low[v]);
		}
		else low[u]=min(low[u],dfn[v]);
	}
}
int pw[N*N>>1],f[N][N],h[N];
void Dfs(int u,int fa)
{
	f[u][siz[u]]=1; 
	for(int v:e[u])
	{
		if(v==fa) continue;
		Dfs(v,u);
		for(int i=0;i<=siz[u];++i) h[i]=0;
		for(int i=0;i<=siz[u];++i)
			for(int j=0;j<=siz[v];++j)
			{
				Madd(h[i+j],Cmul(pw[i*j-1],f[u][i],f[v][j]));
				Madd(h[j],Cmul(f[u][i],f[v][j]));
			}
		siz[u]+=siz[v];	
		for(int i=0;i<=siz[u]+siz[v];++i) f[u][i]=h[i];
	}
}
void Solve()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i)
	{
		int u,v; cin>>u>>v;
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	Tarjan(1,0); Work(1); 
	for(int i=1;i<=n;++i)
		for(PII k:g[i])
		{
			int j=k.fi;
			if(col[i]==col[j]){cnt[col[i]]++;continue;}
			e[col[i]].push_back(col[j]);
		} 
	int tot=0,ans=0,inv2=ksm(2,MOD-2); 
	for(int i=1;i<=idx;++i)
		tot=Cdel(Cmul(siz[i],siz[i]-1,inv2),Cmul(cnt[i],inv2));
	pw[0]=1; for(int i=1;i<=n*(n-1)/2;++i) pw[i]=Cmul(pw[i-1],2);
	Dfs(1,0); 
	for(int i=1;i<=n;++i) Madd(ans,f[1][i]);
	cout<<Cmul(ans,pw[tot])<<'\n';
}
bool M2;
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int T=clock();
	int t=1; //cin>>t;
	while(t--) Solve();
	See_Memory; See_Time;
	Nai_Long;
}







Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6152kb

input:

3 2
1 2
2 3

output:

6

result:

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