QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#758726#5307. Subgraph Isomorphismeinekleine18WA 59ms3648kbC++202.5kb2024-11-17 19:29:522024-11-17 19:29:52

Judging History

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

  • [2024-11-17 19:29:52]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:3648kb
  • [2024-11-17 19:29:52]
  • 提交

answer

#include<bits/stdc++.h>

#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif

#define int long long
typedef unsigned long long ull;
const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
void solve(){
    int n,m;
    std::cin>>n>>m;
    std::vector g(n,std::vector<int>());
    std::vector<int>du(n);
    for(int i=0;i<m;++i){
        int a,b;
        std::cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
        ++du[a];
        ++du[b];
    }
    if(m==n-1){
        std::cout<<"YES\n";
        return;
    }
    if(m>n){
        std::cout<<"NO\n";
        return;
    }
    std::queue<int>q;
    std::vector<int>st(n);
    int sz=n;
    for(int i=0;i<n;++i){
        if(du[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int t=q.front();q.pop();
        st[t]=1;
        --sz;
        for(auto &x:g[t]){
            if(--du[x]==1){
                q.push(x);
            }
        }
    }
    auto shift=[&](ull x)->ull {
        x^=mask;
        x^=x<<13;
        x^=x>>7;
        x^=x<<17;
        x^=mask;
        return x;
    };
    auto hash=[&](auto self,int u,int fa)->ull {
        ull res=1;
        for(auto &x:g[u]){
            if(x==fa||!st[x]) continue;
            ull son=self(self,x,u);
            res+=shift(son);
        }
        return res;
    };
    std::vector<ull>tr;
    int root=-1;
    for(int i=0;i<n;++i){
        if(!st[i]){
            root=i;
            break;
        }
    }
    int last=-1;
    for(int i=0;i<sz;++i){
        tr.push_back(hash(hash,root,-1));
        for(auto &x:g[root]){
            if(x!=last){
                last=root;
                root=x;
                break;
            }
        }
    }
    sz=tr.size();
    for(int i=0;i<sz;++i){
        if(tr[i]!=tr[(i+2)%sz]){
            std::cout<<"NO\n";
            return;
        }
    }
    std::cout<<"YES\n";
}
signed main(){
    // freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    // std::cout<<std::fixed<<std::setprecision(12);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);std::cout.tie(nullptr);
    int _=1;
    std::cin>>_;
    // clock_t start=clock();
    for(int i=1;i<=_;++i){
        solve();
    }
    // clock_t end=clock();
    // double time=static_cast<double>(end-start)/CLOCKS_PER_SEC;
    // std::cout<<time<<'\n';
    return 0;
}

详细

Test #1:

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

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

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
NO
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 [60th token]