QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279254 | #5307. Subgraph Isomorphism | one_god_and_two_dogs# | WA | 38ms | 31076kb | C++20 | 1.5kb | 2023-12-08 14:43:38 | 2023-12-08 14:43:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
const ull mask= chrono::steady_clock::now().time_since_epoch().count();
ull shift(ull x){
x^=mask;
x^=x<<13;
x^=x>>7;
x^=x<<17;
x^=mask;
return x;
}
const int M=1e6+01;
vector<int>G[M];
int ind[M];
ull cir[M];
ull dfs(int x,int f){
ull h=1;
for(auto y:G[x]){
if(y==f)continue;
if(ind[y])continue;
h+=shift(dfs(y,x));
}
return h;
}
bool mk[M];
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;++i){
int a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
ind[a]++,ind[b]++;
}
if(m<n)cout<<"YES\n";
if(m>n)cout<<"NO\n";
if(m==n){
queue<int>que;
for(int i=1;i<=n;++i)if(ind[i]==1)que.push(i);
while(!que.empty()){
int x=que.front();
que.pop();
for(auto y:G[x]){
--ind[y],--ind[x];
if(ind[y]==1)que.push(y);
}
}
int cnt=0;
for(int i=1;i<=n;++i)if(ind[i]){
queue<int>que;
que.push(i);
while(!que.empty()){
int x=que.front();
que.pop();
mk[x]=1;
cir[++cnt]=dfs(x,0);
//cout<<x<<" "<<cir[cnt]<<endl;
for(auto y:G[x]){
if(!mk[y]&&ind[y]){
que.push(y);
break;
}
}
}
break;
}
bool ans=1;
for(int i=2;i<=cnt;++i)
if(cir[i]!=cir[i-1])
ans=0;
if(ans==0&&cnt%2==0){
ans=1;
for(int i=3;i<=cnt;++i)
if(cir[i]!=cir[i-2])
ans=0;
}
cout<<(ans?"YES":"NO")<<"\n";
}
for(int i=1;i<=n;++i)G[i].clear(),ind[i]=mk[i]=0;
}
int main(){
//freopen("hayasa","r",stdin);
cin.tie(0)->sync_with_stdio(0);
int T;
cin>>T;
while(T--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 29888kb
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: 38ms
memory: 31076kb
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 YES 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 YES YES YES YES NO YES NO NO NO NO NO NO YES 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 ...
result:
wrong answer expected NO, found YES [19th token]