QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107038#5307. Subgraph IsomorphismSmallBlackWA 5ms5788kbC++142.5kb2023-05-20 09:28:522023-05-20 09:28:56

Judging History

你现在查看的是测评时间为 2023-05-20 09:28:56 的历史记录

  • [2023-10-15 17:25:13]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:9ms
  • 内存:6280kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 09:28:56]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:5788kb
  • [2023-05-20 09:28:52]
  • 提交

answer

// Problem: D - Subgraph Isomorphism
// Contest: Virtual Judge - 过什么520做题要紧
// URL: https://vjudge.net/contest/559671#problem/D
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// Date:2023-05-20 07:53:15
// By:SmallBlack
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long s=0,k=1;
	char c=getchar();
	while(!isdigit(c))
	{
		k=(c=='-')?-1:1;
		c=getchar();
	}
	while(isdigit(c))
	{
		s=s*10+c-'0';
		c=getchar();
	}
	return s*k;
}
#define d read()
#define ll long long
#define ull unsigned long long
#define Maxn 10010
#define Size 100010
#define mp make_pair
#define pb push_back
#define fi first
#define se second
vector<ll>e[Size];
vector<ll>st,loop;
bool ins[Size],fin=0;
void dfs(ll u,ll fa)
{
	ins[u]=1,st.pb(u);
	for(auto v:e[u])
	{
		if(v==fa) continue;
		if(ins[v])
		{
			while(st.back()!=v)
			{
				loop.pb(st.back());
				st.pop_back();
			}
			loop.pb(v);
			fin=1;
			return;
		}
		dfs(v,u);
		if(fin) return;
	}
	st.pop_back(),ins[u]=0;
}
const ull mask=std::chrono::steady_clock::now().time_since_epoch().count();
ull shift(ull x)
{
	x=x^mask^((x^mask)<<13),x^=x>>7,x^=x<<17;
	return x^mask;
}
ull tag[Size];
ull ksm(ull a,ull b)
{
	ull ans=1;
	while(b)
	{
		if(b&1) ans=ans*a;
		a=a*a,b>>=1;
	}
	return ans;
}
void Hash(ll u,ll fa)
{
	tag[u]=1;
	for(auto v:e[u])
	{
		if(v==fa||ins[v]) continue;
		Hash(v,u);
		tag[u]+=ksm(tag[v],20070529);
	}
}
void solve()
{
	ll n=d,m=d;
	for(int i=1;i<=n;i++) e[i].clear(),ins[i]=0,tag[i]=0;
	for(int i=0;i<m;i++)
	{
		ll x=d,y=d;
		e[x].pb(y),e[y].pb(x);
	}
	if(m==n-1) return (void)puts("YES");
	else if(m>n) return (void)puts("NO");
	fin=0,st.clear(),loop.clear(),dfs(1,0);
	for(int i=1;i<=n;i++) ins[i]=0;
	for(auto x:loop) ins[x]=1;
	if(loop.size()==n) return (void)puts("YES");
	ll cnt=0;
	for(auto x:loop) Hash(x,0),cnt+=(int)(tag[x]!=1);
	if(cnt==1) return (void)puts("NO");
	unsigned ll same=0;
	ll fir=-1,last=-1,dis=-1;
	for(int i=0;i<loop.size();i++)
	{
		if(tag[loop[i]]==1) continue;
		if(same==0) same=tag[loop[i]];
		else if(same!=tag[loop[i]])
			return (void)puts("NO");
		if(fir==-1) fir=i;
		if(last==-1) last=i;
		else if(dis==-1) dis=i-last,last=i;
		else if(dis!=i-last)
			return (void)puts("NO");
		else last=i;
	}
	if(dis!=fir+loop.size()-last) return (void)puts("NO");
	if(dis>2) return (void)puts("NO");
	puts("YES");
}
int main()
{
	ll t=d;
	while(t--) solve();
}

详细

Test #1:

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

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: 5ms
memory: 5788kb

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
YES
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 NO, found YES [1041st token]