QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787707#7324. Eulerian OrientationWorld_CreaterRE 0ms0kbC++171.9kb2024-11-27 14:08:362024-11-27 14:08:39

Judging History

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

  • [2024-11-27 14:08:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-27 14:08:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef unsigned long long ull;
mt19937_64 rnd(random_device{}());
int n,m,nxt[400005],head[200005],go[400005],id[400005],k,pw[200005],cnt,vis[200005],ans;
pair<int,int> a[200005];
ull val[200005],tval[200005];
map<ull,int> mp;
int low[200005],dfn[200005],idx;
void add(int u,int v,int w)
{
	nxt[++k]=head[u];
	head[u]=k;
	go[k]=v;
	id[k]=w;
}
void tarjan(int x)
{
	low[x]=dfn[x]=++idx;
	for(int i=head[x];i;i=nxt[i])
	{
		int g=go[i],w=id[i];
		if(vis[w]) continue ;
		if(!dfn[g])
		{
			vis[w]=1;
			tarjan(g);
		}
		else if(!val[w])
		{
			val[w]=rnd();
			tval[x]^=val[w];
			tval[g]^=val[w];
		}
	}
}
void dfs(int x,int fa)
{
	for(int i=head[x];i;i=nxt[i])
	{
		int g=go[i],w=id[i];
		if(!vis[id[i]]) continue ;
		if(g==fa) continue ;
		dfs(g,x);
		val[w]=tval[g];
		tval[x]^=tval[g];
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("problem.in","r",stdin);
	freopen("problem.out","w",stdout);
	pw[0]=1;
	for(int i=1;i<=200000;i++)
	{
		pw[i]=pw[i-1]<<1;
		if(pw[i]>=mod) pw[i]-=mod;
	}
	while(cin>>n>>m)
	{
		ans=0;
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			a[i]={u,v};
			add(u,v,i);
			add(v,u,i);
		}
		for(int i=1;i<=n;i++)
		{
			if(!dfn[i])
			{
				cnt++;
				tarjan(i);
				dfs(i,0);
			}
		}
		int bs=n-cnt;
		for(int i=1;i<=m;i++)
		{
			mp[val[i]]++;	
		}
		for(int i=1;i<=m;i++)
		{
			if(!val[i]) continue ;
			int c1=mp[val[i]],c2=m-c1-mp[0];
			ans+=1ll*c1*pw[m-bs-1]%mod;
			if(ans>=mod) ans-=mod;
			if(m-bs-2>=0) ans+=1ll*c2*pw[m-bs-2]%mod;
			if(ans>=mod) ans-=mod;
		}
		cout<<ans<<"\n";
		mp.clear();
		idx=0;
		k=0;
		cnt=0;
		ans=0;
		for(int i=1;i<=n;i++)
		{
			head[i]=low[i]=dfn[i]=tval[i]=0;
		}
		for(int i=1;i<=m;i++)
		{
			val[i]=vis[i]=0;
			a[i]={0,0};
		}
		mp.clear();
	}
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

4 4
1 2
1 3
1 4
2 3
6 6
1 2
2 3
3 1
4 5
5 6
6 4
2 3
1 1
1 2
1 2

output:


result: