QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88325#5745. Graph IsomorphismchangtuWA 22ms5824kbC++201.1kb2023-03-15 21:36:272023-03-15 21:36:27

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 21:36:27]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:5824kb
  • [2023-03-15 21:36:27]
  • 提交

answer

#include <set>
#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];

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<=m;i++) {
        int u,v;
        cin>>u>>v;
        hsh[u]^=rnd[v];
        hsh[v]^=rnd[u];
    }
    
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 5692kb

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
NO

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 22ms
memory: 5824kb

input:

39982
3 2
2 1
3 2
2 1
1 2
2 1
2 1
3 3
3 1
2 3
1 2
2 1
1 2
3 3
3 1
3 2
2 1
2 1
1 2
3 2
1 2
3 1
3 3
2 1
3 1
2 3
2 1
1 2
3 2
2 1
3 2
3 3
2 3
3 1
2 1
3 3
2 1
1 3
2 3
3 3
3 1
3 2
1 2
2 1
2 1
2 1
2 1
3 1
3 1
2 1
2 1
2 1
1 2
3 2
1 3
3 2
3 2
1 2
1 3
3 2
3 2
1 3
2 1
1 2
3 2
3 2
3 1
3 3
2 3
3 1
1 2
2 1
1 2
3 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

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

Test #3:

score: -100
Wrong Answer
time: 22ms
memory: 5764kb

input:

33365
3 3
3 1
2 3
2 1
2 1
2 1
4 6
1 2
3 4
4 2
2 3
3 1
4 1
2 1
1 2
2 1
1 2
4 5
1 4
1 2
4 2
3 4
1 3
4 3
4 2
2 1
1 3
3 1
3 2
4 3
1 3
1 2
3 4
3 3
3 2
3 1
2 1
3 1
2 3
3 1
1 3
3 1
2 1
3 2
1 3
3 2
4 5
3 1
4 2
3 4
2 3
2 1
4 2
1 2
3 2
2 1
2 1
3 2
1 2
2 3
3 1
3 2
4 1
3 4
3 1
2 1
4 3
1 2
4 2
3 2
2 1
2 1
4 5
3 ...

output:

YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
...

result:

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