QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660655#5307. Subgraph IsomorphismDark_nightWA 63ms11332kbC++142.0kb2024-10-20 12:34:102024-10-20 12:34:12

Judging History

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

  • [2024-10-20 12:34:12]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:11332kb
  • [2024-10-20 12:34:10]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const ll mod=1e9+7;

int _,n,m;
int st[100005],hd,len;
int num[100005],cir[100005],siz[100005];
ll hsh[100005],base[100005];
bool vis[100005];
vector<int> adj[100005],bdj[100005];

inline void dfs(int u,int fa)
{
    st[++hd]=u;
    num[u]=hd;

    for(int v:adj[u])
    {
        if(v==fa)
            continue;

        if(num[v])
        {
            for(int j=num[v];j<=hd;j++)
                vis[cir[++len]=st[j]]=1;
            
            continue;
        }

        dfs(v,u);
    }

    hd--;
}

inline bool cmp(int x,int y){return hsh[x]<hsh[y];}

inline void gethsh(int u)
{
    siz[u]=vis[u]=1;

    for(int v:adj[u])
    {
        if(vis[v])
            continue;

        bdj[u].push_back(v);
        gethsh(v);
        siz[u]+=siz[v];
    }

    hsh[u]=siz[u]-1;
    sort(bdj[u].begin(),bdj[u].end(),cmp);

    for(int v:bdj[u])
        hsh[u]=(hsh[u]*base[siz[v]]+hsh[v])%mod;
}

inline void sol()
{
    cin>>n>>m;

    base[0]=1;
    for(int i=1;i<=n;i++)
        adj[i].clear(),bdj[i].clear(),num[i]=vis[i]=0,base[i]=base[i-1]*n%mod;

    while(m--)
    {
        int u,v;
        cin>>u>>v;

        adj[u].push_back(v),adj[v].push_back(u);
    }

    if(m==n-1)
    {
        cout<<"YES\n";
        return;
    }

    if(m>n)
    {
        cout<<"NO\n";
        return;
    }

    hd=len=0;
    dfs(1,0);

    for(int i=1;i<=len;i++)
        gethsh(cir[i]);

    bool f=1;

    if(len&1)
    {
        for(int i=2;i<=len;i++)
            f&=(hsh[cir[i-1]]==hsh[cir[i]]);
    }
    else
    {
        for(int i=3;i<=len;i+=2)
            f&=(hsh[cir[i-2]]==hsh[cir[i]]&&hsh[cir[i-1]]==hsh[cir[i+1]]);
    }

    if(f)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    cin>>_;

    while(_--)
        sol();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11332kb

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

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

result:

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