QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88325 | #5745. Graph Isomorphism | changtu | WA | 22ms | 5824kb | C++20 | 1.1kb | 2023-03-15 21:36:27 | 2023-03-15 21:36:27 |
Judging History
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;
}
详细
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]