QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#223665#5433. Absolute DifferencelzlwddlWA 0ms14788kbC++232.2kb2023-10-22 15:02:002023-10-22 15:02:00

Judging History

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

  • [2023-10-22 15:02:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14788kb
  • [2023-10-22 15:02:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+7;
#define int unsigned long long
int head[maxn],ver[maxn],net[maxn],cnt,top;
int dp[maxn];
void add(int x,int y){
	ver[++cnt]=y;
	net[cnt]=head[x];
	head[x]=cnt;
}
int h(int x) {
    return x * x * x * 1237123 + 19260817;
}
int f(int x) {
    int cur = h(x & ((1ll << 31) - 1)) + h(x >> 31);
    return cur;
}
int isp[maxn],siz[maxn],prime[maxn],c[maxn],tot;
void isprime(){
	for(int i=2;i<=5e5;i++){
		if(!c[i]){
			c[i]=i;
			prime[++tot]=i;
		}
		for(int j=1;j<=tot;j++){
                        if(c[i]<prime[j]||i*prime[j]>5e5)break;
                        c[i*prime[j]]=prime[j];
		}
	}
}
void dfs(int x,int f){
	dp[x]=1;
	siz[x]=1;
	for(int i=head[x];i;i=net[i]){
		int y=ver[i];
		if(y==f||isp[y]>1)continue;
		dfs(y,x);
		dp[x]+=dp[y]*prime[siz[y]];
		siz[x]+=siz[y];
	}
	//cout<<x<<" "<<siz[x]<<" "<<dp[x]<<" "<<prime[siz[x]]<<endl;
}
int sta[maxn];
void dfs1(int x,int f,int ff){
	sta[++top]=x;
	for(int i=head[x];i;i=net[i]){
		int y=ver[i];
		if(y==f||isp[y]==1)continue;
		if(y==ff)return ;
		dfs1(y,x,ff);
		return ;
	}
}
void solve(){
	int n,m;
	cin>>n>>m;cnt=0;
	for(int i=1;i<=n;i++)isp[i]=head[i]=0;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
  		add(u,v);
		add(v,u);
		isp[u]++;isp[v]++;
	}
	if(m>n){
		cout<<"NO\n";
		return ;
	}
	if(m==n-1){
		cout<<"YES\n";
		return ;
	}
	queue <int> q;
	for(int i=1;i<=n;i++)
	if(isp[i]==1)q.push(i);
	while(q.size()){
		int x=q.front();q.pop();
		for(int i=head[x];i;i=net[i]){
			int y=ver[i];
			isp[y]--;
			if(isp[y]==1)q.push(y);
		}
	}
	int num=0;
	for(int i=1;i<=n;i++)
	if(isp[i]>1)dfs(i,i),num++;
	int la=0;
	if(num&1){
		for(int i=1;i<=n;i++)
		if(isp[i]>1){
			if(!la)la=dp[i];
			else if(la!=dp[i]){
				cout<<"NO\n";
				return ;
			}
		}
	}
	else {
		int rt;top=0;
		for(int i=1;i<=n;i++)
		if(isp[i]>1)rt=i;
		dfs1(rt,rt,rt);
		for(int i=3;i<=top;i++)
		if(dp[sta[i]]==dp[sta[i-2]]);
		else {
			cout<<"NO\n";
			return ;
		}
		if(dp[sta[2]]!=dp[sta[top]]||dp[sta[1]]!=dp[sta[top-1]]){
			cout<<"NO\n";
			return ;
		}
	}
	cout<<"YES\n";
}
signed main(){
	int t;
	cin>>t;
	isprime();
	while(t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 14788kb

input:

1 1
0 1
0 1

output:

YES

result:

wrong output format Expected double, but "YES" found