QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672494#5307. Subgraph Isomorphismbessie_goes_moo#WA 11ms5720kbC++171.8kb2024-10-24 17:02:192024-10-24 17:02:20

Judging History

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

  • [2024-10-24 17:02:20]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5720kb
  • [2024-10-24 17:02:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,E=N<<1;
typedef unsigned long long ull;
int read(){
	int red=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){ if(ch=='-') f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') red=red*10+ch-48,ch=getchar();
	return red*f;
}
int T,n,m;
int son[E],nxt[E],lnk[N],tot;
void add_e(int x,int y){
    son[++tot]=y,nxt[tot]=lnk[x],lnk[x]=tot;
}
int fa[N];bool vis[N],isH[N],findH;
#define v son[j]
void find(int x){
    vis[x]=1;
    for(int j=lnk[x];j&&!findH;j=nxt[j]) {
        if(!vis[v]){
            fa[v]=x;find(v);
        }else if(v^fa[x]){
            for(;x!=v;x=fa[x]) isH[x]=1;
            isH[v]=1;findH=1;
            return;
        }
    }
}
const ull mask=mt19937_64(time(nullptr))();
ull shift(ull x) {
    x ^= mask;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    x ^= mask;
    return x;
}
ull hsh[N],HASH;bool flg;
void getHash(int x,int p=0){
    hsh[x]=1;
    for(int j=lnk[x];j;j=nxt[j]) if(v!=p&&!isH[v]){
        getHash(v,x);
        hsh[x]+=shift(hsh[v]);
    }
}
void clear(){
    memset(lnk,0,sizeof(int)*(n+1));
    memset(vis,0,sizeof(bool)*(n+1));
    memset(isH,0,sizeof(bool)*(n+1));
    tot=flg=findH=0;
}
int main(){
    T=read();
    while(T--){
        clear();n=read(),m=read();
        for(int i=1;i<=m;i++){
            int x=read(),y=read();
            add_e(x,y),add_e(y,x);
        }
        if(m==n-1) puts("YES");else
        if(m>n) puts("NO");else{
            find(1);bool ok=1;
            for(int i=1;i<=n;i++) if(isH[i]){
                getHash(i);
                if(!flg) flg=1,HASH=hsh[i];
                if(HASH!=hsh[i]) ok=0;
            }
            puts(ok?"YES":"NO");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5720kb

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: 3752kb

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]