QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607506#5307. Subgraph Isomorphism999#WA 51ms22420kbC++142.1kb2024-10-03 15:05:452024-10-03 15:05:45

Judging History

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

  • [2024-10-03 15:05:45]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:22420kb
  • [2024-10-03 15:05:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define M 300005
#define P1 19260817
#define P2 1000000007
#define K1 13448
#define K2 3213458
int n,m,deg[M],sk[M],mk[M],pw1[M],pw2[M],sz=0,us[M];
struct hh{
	int hs1,hs2,sz;
	hh operator+(hh x)const{
		hh a;
		a.hs1=(1ll*hs1*pw1[x.sz]+x.hs1)%P1;
		a.hs2=(1ll*hs2*pw2[x.sz]+x.hs2)%P2;
		a.sz=sz+x.sz;
		return a;
	}
	bool operator!=(hh x)const{
		return hs1!=x.hs1||hs2!=x.hs2||sz!=x.sz;
	}
	bool operator<(hh x)const{
		if(hs1==x.hs1)return hs2<x.hs2;
		return hs1<x.hs1;
	}
}dp[M],now,ac[M],fk[M];
vector<int>d[M];
void init(){
	sz=0;
	for(int i=1;i<=n;++i)deg[i]=0,d[i].clear(),us[i]=0;
}
void dfs(int x,int f){
	for(int i=0;i<(int)d[x].size();++i){
		int v=d[x][i];
		if(mk[v]||v==f)continue;
		dfs(v,x);
	}
	int cnt=0;
	for(int i=0;i<(int)d[x].size();++i){
		int v=d[x][i];
		if(mk[v]||v==f)continue;
		ac[++cnt]=dp[v];
	}
	sort(ac+1,ac+cnt+1);
	dp[x]=(hh){3,3,1};
	for(int i=1;i<=cnt;++i)dp[x]=dp[x]+ac[i];
	dp[x]=dp[x]+(hh){2,2,1};
}
void Dfs(int x){
	dfs(x,0);
	fk[++sz]=dp[x];us[x]=1;
	for(int i=0;i<(int)d[x].size();++i){
		int v=d[x][i];
		if(!mk[v]||us[v])continue;
		Dfs(v);
	}
}
void solve(){
	init();
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;++i){
		scanf("%d%d",&x,&y);
		d[x].push_back(y);
		d[y].push_back(x);
		deg[x]++;deg[y]++;
	}
	if(m>n){
		puts("NO");
		return;
	}
	if(m==n-1){
		puts("YES");
		return;
	}
	int cnt=0;
	for(int i=1;i<=n;++i)if(deg[i]==1)sk[++cnt]=i;
	int l=1,r=0;
	while(l<=r){
		int p=sk[l++];
		for(int i=0;i<(int)d[p].size();++i){
			int v=d[p][i];
			deg[v]--;
			if(deg[v]==1)sk[++r]=v;
		}
	}
	for(int i=1;i<=n;++i)mk[i]=deg[i]>=2;
	sz=0;
	for(int i=1;i<=n;++i)if(mk[i]){
		Dfs(i);
		break;
	}
	for(int i=2;i<=sz;++i){
		if(sk[i]!=sk[1]){
			int f=sz&1;
			for(int j=1;j+2<=sz&&!f;j+=2){
				f|=(fk[j]!=fk[j+2]);
				f|=(fk[j+1]!=fk[j+3]);
			}
			if(f){
				puts("NO");
				return;
			}
			break;
		}
	}
	puts("YES");
}
int main(){
	pw1[0]=pw2[0]=1;
	for(int i=1;i<M;++i)pw1[i]=1ll*K1*pw1[i-1]%P1,pw2[i]=1ll*K2*pw2[i-1]%P2;
	int t;
	scanf("%d",&t);
	while(t--)solve();
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 22420kb

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: 51ms
memory: 18928kb

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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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
NO
NO
N...

result:

wrong answer expected YES, found NO [23rd token]