QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107246#5307. Subgraph IsomorphismshihoghmeanWA 11ms94044kbC++143.2kb2023-05-20 16:27:242023-10-15 17:25:32

Judging History

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

  • [2023-10-15 17:25:32]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:11ms
  • 内存:94044kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 16:27:25]
  • 评测
  • 测评结果:0
  • 用时:43ms
  • 内存:93764kb
  • [2023-05-20 16:27:24]
  • 提交

answer

// Problem: G. Subgraph Isomorphism
// Contest: Codeforces - The 2022 ICPC Asia Hangzhou Regional Programming Contest
// URL: https://codeforces.com/gym/104090/problem/G
// Memory Limit: 1024 MB
// Time Limit: 3000 ms

#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define py puts("YES")
#define pn puts("NO")
#define pt puts("")
#define pb push_back
#define wt(x) write(x),puts("")
#define wr(x) write(x) ,putchar(' ')
#define tx printf("fds")
#define mp make_pair
#define fi first
#define se second
inline int read(){
	int x=0,k=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') k=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+ch-48;
		ch=getchar();
	}
	return x*k;
}
void write(int x){
	if(x<0){
		x=-x;
		putchar('-');
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
int power(int x,int y,int mod){
	int num=1;
	while(y){
		if(y&1) num=(num*x)%mod;
		x=x*x%mod;
		y>>=1;
	}
	return num;
}
int mul(int x,int y,int mod){
	int num=0;
	while(y){
		if(y&1) num=(num+x)%mod;
		x=(x+x)%mod;
		y>>=1;
	}
	return num;
}
const int N=1e6+7,mod=998244353;
int n,m,tot,tot1;
int head[N];
struct edge{
	int to,next;
}e[N];
void add(int u,int v){
	e[++tot]={v,head[u]};
	head[u]=tot;
}
int vis[N],is_round[N],END,siz[N],st[N],top,f[N];
int p[10000001],prime[N];
void pre(){
	for(int i=2;i<=10000000;i++){
		if(!p[i]) prime[++tot1]=i;
		for(int j=1;j<=tot1&&i*prime[j]<=n;j++){
			p[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}
void dfs(int u,int fa){
	if(vis[u]){
		while(st[top]!=u){
			is_round[st[top]]=1;
			top--;
		}
		is_round[u]=1;
		END=1;
		return ;
	}
	vis[u]=1;
	st[++top]=u;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u);
		if(END) return ;
		while(st[top]!=u){
			top--;
		}
	}
}
void dfs1(int u,int fa){
	f[u]=1;
	siz[u]=1;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(is_round[v]||v==fa) continue;
		dfs1(v,u);
		siz[u]+=siz[v];
		f[u]+=f[v]*prime[siz[v]];
	}
}
void dfs2(int u,int fa){
	st[++top]=u;
	vis[u]=1;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa||vis[v]||!is_round[v]) continue;
		dfs2(v,u);
	}
}
bool solve(){
	fo(i,1,n) vis[i]=0,is_round[i]=0,siz[i]=0,f[i]=0;
	END=0;
	top=0;
	dfs(1,0);
	top=0;
	fo(u,1,n){
		if(is_round[u]) dfs1(u,0);
		vis[u]=0;
	}
	fo(u,1,n){
		if(is_round[u]){
			dfs2(u,0);
			break;
		}
	}
	int fl=0,fll=0;
	fo(i,2,top){
		if(f[st[i]]!=f[st[i-1]]) fl=1;
	}
	// wr(top);
	if(!fl){
		return true;
	}
	if(top%2==1) return true;
	fo(i,1,top){
		if(i==1){
			if(f[st[i]]!=f[st[top-1]]) fll=1;
		}
		else if(i==2){
			if(f[st[i]]!=f[st[top]]) fll=1;
		}
		else{
			if(f[st[i]]!=f[st[i-2]]) fll=1;
		}
	}
	if(!fl) return true;
	return false;
}
signed main(){
	pre();
	int tt=read();
	while(tt--){
		n=read();m=read();
		fo(i,0,tot) head[i]=0;
		tot=0;
		fo(i,1,m){
			int x=read(),y=read();
			add(x,y);add(y,x);
		}
		if(m==n-1){
			py;
			continue;
		}
		if(m>n){
			pn;
			continue;
		}
		if(solve()) py;
		else pn;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 94044kb

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: 11ms
memory: 94044kb

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

result:

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