QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88329#5745. Graph IsomorphismchangtuWA 4ms5704kbC++231.4kb2023-03-15 22:10:292023-03-15 22:10:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-15 22:10:29]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5704kb
  • [2023-03-15 22:10:29]
  • 提交

answer

#include <map>
#include <random>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define endl '\n'
using LL=long long;
using ULL=unsigned long long;
constexpr int N=1e5+10;
vector<int> adj[N];
mt19937_64 gen=mt19937_64(random_device{}());
ULL rnd[N],hsh[N];
int ind[N];

void solve() {
    int n,m;
    cin>>n>>m;
    LL tot=1LL*n*(n-1)/2+1;
    for(int i=1;i<=n;i++) rnd[i]=gen();
    for(int i=1;i<=n;i++) hsh[i]=0;
    for(int i=1;i<=n;i++) ind[i]=0;
    for(int i=1;i<=m;i++) {
        int u,v;
        cin>>u>>v;
        ind[u]++,ind[v]++;
        hsh[u]^=rnd[v];
        hsh[v]^=rnd[u];
    }

    auto patch=[&]() {
        for(int i=1;i<=4;i++) if(ind[i]!=2) return false;
        return true;
    };
    if(patch()) {
        cout<<"YES"<<endl;
        return;
    }

    map<ULL,int> cnt;
    for(int i=1;i<=n;i++) cnt[hsh[i]]++;
    for(auto [_,x]:cnt) tot-=1LL*x*(x-1)/2;

    for(int i=1;i<=n;i++) hsh[i]^=rnd[i];
    cnt.clear();
    for(int i=1;i<=n;i++) cnt[hsh[i]]++;
    for(auto [_,x]:cnt) tot-=1LL*x*(x-1)/2;

    LL num=0;
    for(auto [_,x]:cnt) if(x==2) num++;
    tot-=num*(num-1);
    if(tot<=n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 5704kb

input:

3
3 3
1 2
2 3
3 1
3 2
1 2
2 3
5 5
1 2
2 3
3 4
4 5
5 1

output:

YES
YES
YES

result:

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