QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279238#5307. Subgraph Isomorphismone_god_and_two_dogs#WA 38ms29616kbC++201.5kb2023-12-08 14:34:452023-12-08 14:34:47

Judging History

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

  • [2023-12-08 14:34:47]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:29616kb
  • [2023-12-08 14:34:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ull=unsigned long long;

const ull mask= chrono::steady_clock::now().time_since_epoch().count();
ull shift(ull x){
	x^=mask;
	x^=x<<13;
	x^=x>>7;
	x^=x<<17;
	x^=mask;
	return x;
}

const int M=1e6+01;
vector<int>G[M];
int ind[M];
ull cir[M];

ull dfs(int x,int f){
	ull h=1;
	for(auto y:G[x]){
		if(y==f)continue;
		if(ind[y])continue;
		h+=shift(dfs(y,x));
	}
	return h;
}
bool mk[M];
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
		ind[a]++,ind[b]++;
	}
	if(m<n)cout<<"YES\n";
	if(m>n)cout<<"NO\n";
	if(m==n){
		queue<int>que;
		for(int i=1;i<=n;++i)if(ind[i]==1)que.push(i);
		while(!que.empty()){
			int x=que.front();
			que.pop();
			for(auto y:G[x]){
				--ind[y],--ind[x];
				if(ind[y]==1)que.push(y);
			}
		}
		int cnt=0;
		for(int i=1;i<=n;++i)if(ind[i]){
			queue<int>que;
			que.push(i);
			while(!que.empty()){
				int x=que.front();
				que.pop();
				mk[x]=1;
				cir[++cnt]=dfs(x,0);
				for(auto y:G[x]){
					if(!mk[y]&&ind[y]){
						que.push(y);
						break;
					}
				}
			}
			break;
		}
		bool ans=1;
		for(int i=2;i<=cnt;++i)
			if(cir[i]!=cir[i-1])
				ans=0;
		if(ans==0&&n%2==0){
			ans=1;
			for(int i=3;i<=cnt;++i)
				if(cir[i]!=cir[i-2])
					ans=0;
		}
		cout<<(ans?"YES":"NO")<<"\n";
	}
	for(int i=1;i<=n;++i)G[i].clear(),ind[i]=mk[i]=0;
}

int main(){
	//freopen("hayasa","r",stdin);
	cin.tie(0)->sync_with_stdio(0);
	int T;
	cin>>T;
	while(T--)solve();

}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 29616kb

input:

4
7 6
1 2
2 3
3 4
4 5
5 6
3 7
3 3
1 2
2 3
3 1
5 5
1 2
2 3
3 4
4 1
1 5
1 0

output:

YES
YES
NO
YES

result:

ok 4 token(s): yes count is 3, no count is 1

Test #2:

score: -100
Wrong Answer
time: 38ms
memory: 27340kb

input:

33192
2 1
1 2
3 2
1 3
2 3
3 3
1 2
1 3
2 3
4 3
1 4
2 4
3 4
4 3
1 3
1 4
2 4
4 4
1 3
1 4
2 4
3 4
4 4
1 3
1 4
2 3
2 4
4 5
1 3
1 4
2 3
2 4
3 4
4 6
1 2
1 3
1 4
2 3
2 4
3 4
5 4
1 5
2 5
3 5
4 5
5 4
1 4
1 5
2 5
3 5
5 5
1 4
1 5
2 5
3 5
4 5
5 5
1 4
1 5
2 4
3 5
4 5
5 5
1 4
1 5
2 4
2 5
3 5
5 6
1 4
1 5
2 4
2 5
3 ...

output:

YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer expected NO, found YES [19th token]