QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108157#5307. Subgraph IsomorphismwhyWA 7ms2280kbC++142.2kb2023-05-23 18:47:462023-05-23 18:47:48

Judging History

你现在查看的是测评时间为 2023-05-23 18:47:48 的历史记录

  • [2023-10-15 17:25:49]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:9ms
  • 内存:3408kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 18:47:48]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:2280kb
  • [2023-05-23 18:47:46]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<time.h>
#include<stdlib.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+86;

int T,n,m;
struct edge{int to,nxt;}e[N<<1];
int head[N],tot;
void add(int u,int v){e[++tot]={v,head[u]},head[u]=tot;}

int rt,nxt[N],st[N],top;
bool vis[N];
bool ring(int u,int fa)
{
    if(vis[u])
    {
        rt=u;
        int now=u;
        while(st[top]!=u) nxt[st[top]]=now,now=st[top],top--;
        nxt[u]=now;
        top--;
        return true;
    }
    st[++top]=u;
    vis[u]=true;
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;
        if(v==fa) continue;
        if(ring(v,u)) return true;
    }
    vis[u]=false;
    top--;
    return false;
}
ull rep[N];
int siz[N];
ull hash_tree(int u,int fa)
{
    ull h=1;
    siz[u]=1;
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;
        if(v==fa||nxt[v]) continue;
        h+=hash_tree(v,u)*siz[v];
        siz[u]+=siz[v];
    }
    return h;
}
bool check()
{
    ull h[2]={hash_tree(rt,0),hash_tree(nxt[rt],0)};
    for(int f=0,now=nxt[nxt[rt]];now!=rt;now=nxt[now],f=!f)
        if(hash_tree(now,0)!=h[f]) return false;
    return true;
}

template<typename T>
inline void read(T &x)
{
    T k=1;char ch=getchar();x=0;
    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();
    x*=k;
}

signed main()
{
    srand(time(NULL));
    read(T);
    for(int i=1;i<=1e5;i++) rep[i]=((ull)rand()<<30)+((ull)rand<<15)+rand();
    while(T--)
    {
        read(n),read(m);
        memset(head+1,0,n<<2);
        memset(nxt+1,0,n<<2);
        memset(vis+1,0,n);
        tot=rt=top=0;
        for(int i=1,u,v;i<=m;i++)
            read(u),read(v),add(u,v),add(v,u);
        if(m>n)
        {
            puts("NO");
            continue;
        }
        if(m==n-1)
        {
            puts("YES");
            continue;
        }
        ring(1,0);
        if(check()) puts("YES");
        else puts("NO");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2172kb

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

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

result:

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