QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642148#5307. Subgraph IsomorphismIcedpiggy#WA 32ms9344kbC++142.4kb2024-10-15 11:02:012024-10-15 11:02:01

Judging History

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

  • [2024-10-15 11:02:01]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:9344kb
  • [2024-10-15 11:02:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
inline i64 rd()
{
	i64 num=0;char ch=getchar();bool op=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')op=1;
	for(;isdigit(ch);ch=getchar())num=num*10+(ch-'0');
	return op?-num:num;
}
inline void pyes(bool ans)
{
	if(ans)printf("YES\n");
	else printf("NO\n");
}

const int m1=998244353,m2=1000000007,m3=1000000009;
inline int Mod(int x,int mod){return x>=mod?x-mod:x;}
inline int ginv(i64 val,int mod){i64 res=1;int p=mod-2;while(p){if(p&1)res=res*val%mod;val=val*val%mod;p>>=1;}return res;}
 
struct H
{
	int L;
	int x,y,z;
	H(){}
	H(int L,int num):L(L),x(num),y(num),z(num){}
	H(int L,int x,int y,int z):L(L),x(x),y(y),z(z){}
};
inline H operator + (const H&A,const H&B){return H(max(A.L,B.L),Mod(A.x+B.x,m1),Mod(A.y+B.y,m2),Mod(A.z+B.z,m3));}
inline H operator * (const H&A,const H&B){return H(A.L+B.L,1ll*A.x*B.x%m1,1ll*A.y*B.y%m2,1ll*A.z*B.z%m3);}
inline bool operator == (const H&A,const H&B){return A.L==B.L&&A.x==B.x&&A.y==B.y&&A.z==B.z;}
inline bool operator < (const H&A,const H&B){return A.L!=B.L?A.L<B.L:(A.x!=B.x?A.x<B.x:(A.y!=B.y?A.y<B.y:A.z<B.z));}

const H B(1,3);
const int N=1e5+10;

H pw[N+N];

int n,m;
vector<int> g[N];
int f[N];
int cA,cB;
bool vis[N];

inline void dfs(int u)
{
	vis[u]=1;
	for(int v:g[u])
	{
		if(f[u]==v)continue;
		if(vis[v]){cA=u,cB=v;continue;}
		f[v]=u,dfs(v);
	}
}
inline H ghsh(int u)
{
	H res(1,1);
	vector<H> ch;
	for(int v:g[u])
		if(v!=f[u]&&!vis[v])
			ch.emplace_back(ghsh(v));
	sort(ch.begin(),ch.end());
	for(H hsh:ch)
		res=res*pw[hsh.L]+hsh;
	res=res*B+H(1,2);
	return res;
}


inline void work()
{
	n=rd(),m=rd();
	for(int i=1;i<=n;i++)vector<int>().swap(g[i]),vis[i]=0,f[i]=0;
	for(int i=1;i<=m;i++)
	{
		int u0=rd(),v0=rd();
		g[u0].emplace_back(v0);
		g[v0].emplace_back(u0);
	}
	if(m<n)return pyes(1);
	if(m>n)return pyes(0);
	
	cA=0,cB=0,dfs(1);
	g[cA].erase(find(g[cA].begin(),g[cA].end(),cB));
	g[cB].erase(find(g[cB].begin(),g[cB].end(),cA));
	
	for(int i=1;i<=n;i++)f[i]=0,vis[i]=0;
	dfs(cA);
	for(int i=1;i<=n;i++)vis[i]=0;
	for(int u=cB;u;u=f[u])vis[u]=1;
	
	vector<H> res;
	for(int u=cB;u;u=f[u])res.emplace_back(ghsh(u));
	
	bool Ans=1;
	for(H hsh:res)Ans&=hsh==res.front();
	pyes(Ans);
}
int main()
{
	n=2e5+10;pw[0]=H(0,1);
	for(int i=1;i<=n;i++)pw[i]=pw[i-1]*B;
	for(int test=rd();test;test--)work();
	return 0;
}

詳細信息

Test #1:

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

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: 32ms
memory: 9344kb

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

result:

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