QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695441#5307. Subgraph IsomorphismGolem__#WA 31ms81064kbC++172.9kb2024-10-31 20:02:472024-10-31 20:02:47

Judging History

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

  • [2024-10-31 20:02:47]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:81064kb
  • [2024-10-31 20:02:47]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

template <typename T>
inline void read(T &s)
{
    s=0;int f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
    s*=f;
}

#define ll long long
#define ull unsigned ll
#define Vint std::vector<int>

struct Hash
{
    ull h1,h2;
    Hash(){}
    Hash(ull ch):h1(ch),h2(ch){}
    Hash(ull _h1,ull _h2):h1(_h1),h2(_h2){}
    Hash operator +(const Hash &rhs)const{return Hash(h1+rhs.h1,h2^rhs.h2);}
    Hash operator *(const ull &rhs)const{return Hash(h1*rhs,h2*rhs);}
    Hash operator *(const Hash &rhs)const{return Hash(h1*rhs.h1,h2*rhs.h2);}
    bool operator ==(const Hash &rhs)const{return h1==rhs.h1&&h2==rhs.h2;}
    bool operator !=(const Hash &rhs)const{return !((*this)==rhs);}
};

const int N=2e6+99;
namespace Pr
{
int cnt,vis[N],prime[N];
void init()
{
    for(int i=2;i<N;i++)
    {
        if(!vis[i])vis[i]=prime[++cnt]=i;
        for(int j=1;j<=cnt;j++)
        {
            if(prime[j]>vis[i]||prime[j]*i>=N)break;
            vis[prime[j]*i]=prime[j];
        }
    }
}
}

const ull Base=97;
ull Bases[N];

Vint G[N],stc;
int vis[N];
int dfs1(int u,int fa)
{
    vis[u]=1;
    for(int v:G[u])
    {
        if(v==fa)continue;
        if(vis[v])return v;
        int ans=dfs1(v,u);
        if(ans)return ans;
    }
    return 0;
}
bool dfs2(int u,int fa)
{
    vis[u]=1;
    for(int v:G[u])
    {
        if(v==fa)continue;
        if(vis[v]||dfs2(v,u))
        {
            stc.push_back(u);
            return 1;
        }
    }
    return 0;
}

Hash F[N];
int Size[N];
void dfs3(int u,int fa)
{
    F[u]=Hash(1);
    Size[u]=1;
    for(int v:G[u])
    {
        if(v==fa||vis[v])continue;
        dfs3(v,u);Size[u]+=Size[v];
        F[u]=F[u]+F[v]*Hash(Pr::prime[Size[v]],1);
    }
}

void work()
{
    int n,m;read(n);read(m);
    for(int u=1;u<=n;u++)G[u].clear(),vis[u]=0;
    for(int i=1;i<=m;i++)
    {
        int u,v;read(u);read(v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if(m>n)return puts("NO"),void();
    if(m==n-1)return puts("YES"),void();
    int rt=dfs1(1,0);
    for(int i=1;i<=n;i++)vis[i]=0;
    stc.clear();dfs2(rt,0);
    for(int u=1;u<=n;u++)vis[u]=0;
    for(int u:stc)vis[u]=1;
    for(int u:stc)dfs3(u,0);
    int f1=1,f2=1;
    for(int i=1;i<(int)stc.size();i++)if(F[stc[0]]!=F[stc[i]])f1=0;
    if(n&1)f2=0;
    for(int i=0;i<(int)stc.size();i+=2)if(F[stc[0]]!=F[stc[i]])f2=0;
    for(int i=1;i<(int)stc.size();i+=2)if(F[stc[1]]!=F[stc[i]])f2=0;
    if(f1||f2)puts("YES");
    else puts("NO");
}

int main()
{
    Bases[0]=1;
    for(int i=1;i<N;i++)Bases[i]=Bases[i-1]*Base;
    //freopen("_.in","r",stdin);
    //freopen("_.ans","w",stdout);
    Pr::init();
    int T;read(T);
    while(T--)work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 28ms
memory: 74956kb

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:

ok 33192 token(s): yes count is 58, no count is 33134

Test #3:

score: 0
Accepted
time: 31ms
memory: 76412kb

input:

40000
9 24
1 4
1 6
1 7
1 9
2 5
2 7
2 8
2 9
3 5
3 7
3 8
3 9
4 6
4 8
4 9
5 6
5 8
5 9
6 7
6 8
6 9
7 8
7 9
8 9
9 21
1 4
1 6
1 7
1 8
2 5
2 7
2 8
2 9
3 5
3 7
3 9
4 6
4 8
4 9
5 6
5 9
6 7
6 8
6 9
7 8
8 9
9 21
1 4
1 6
1 7
1 8
2 5
2 7
2 8
2 9
3 5
3 7
3 9
4 6
4 8
4 9
5 6
5 9
6 7
6 8
6 9
7 8
7 9
9 22
1 4
1 6
1 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 40000 token(s): yes count is 0, no count is 40000

Test #4:

score: 0
Accepted
time: 31ms
memory: 76112kb

input:

40000
9 16
1 4
1 6
1 8
1 9
2 5
2 7
2 8
2 9
3 6
3 7
4 7
5 8
6 9
7 8
7 9
8 9
9 16
1 4
1 6
1 8
1 9
2 5
2 7
2 8
2 9
3 6
3 7
4 7
5 8
5 9
7 8
7 9
8 9
9 16
1 4
1 6
1 8
1 9
2 5
2 7
2 8
2 9
3 6
3 7
4 7
5 8
5 9
6 9
7 8
8 9
9 16
1 4
1 6
1 8
1 9
2 5
2 7
2 8
2 9
3 6
3 7
4 7
5 8
5 9
6 9
7 8
7 9
9 17
1 4
1 6
1 8
1...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 40000 token(s): yes count is 0, no count is 40000

Test #5:

score: 0
Accepted
time: 30ms
memory: 75408kb

input:

40000
9 17
1 5
1 6
1 7
1 8
2 5
2 7
2 9
3 6
3 8
3 9
4 7
4 8
4 9
5 7
5 8
5 9
6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O
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 40000 token(s): yes count is 0, no count is 40000

Test #7:

score: 0
Accepted
time: 24ms
memory: 74972kb

input:

40000
9 15
1 5
1 8
1 9
2 6
2 7
2 9
3 6
3 7
4 7
4 8
4 9
5 8
6 9
7 9
8 9
9 13
1 5
1 8
1 9
2 6
2 7
2 9
3 6
3 7
4 7
4 8
4 9
5 8
5 9
9 14
1 5
1 8
1 9
2 6
2 7
2 9
3 6
3 7
4 7
4 8
4 9
5 8
5 9
8 9
9 14
1 5
1 8
1 9
2 6
2 7
2 9
3 6
3 7
4 7
4 8
4 9
5 8
5 9
7 9
9 15
1 5
1 8
1 9
2 6
2 7
2 9
3 6
3 7
4 7
4 8
4 9
5...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 40000 token(s): yes count is 1, no count is 39999

Test #8:

score: -100
Wrong Answer
time: 20ms
memory: 76936kb

input:

40000
9 8
1 9
2 9
3 9
4 9
5 9
6 9
7 9
8 9
9 8
1 8
1 9
2 9
3 9
4 9
5 9
6 9
7 9
9 9
1 8
1 9
2 9
3 9
4 9
5 9
6 9
7 9
8 9
9 8
1 8
2 8
3 9
4 9
5 9
6 9
7 9
8 9
9 8
1 8
1 9
2 8
3 9
4 9
5 9
6 9
7 9
9 9
1 8
1 9
2 8
3 9
4 9
5 9
6 9
7 9
8 9
9 9
1 8
1 9
2 8
2 9
3 9
4 9
5 9
6 9
7 9
9 10
1 8
1 9
2 8
2 9
3 9
4 9
5...

output:

YES
YES
NO
YES
YES
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
N...

result:

wrong answer expected YES, found NO [673rd token]