QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279232 | #5307. Subgraph Isomorphism | one_god_and_two_dogs# | WA | 44ms | 26916kb | C++20 | 1.5kb | 2023-12-08 14:31:03 | 2023-12-08 14:31:04 |
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);
for(auto y:G[x]){
if(!mk[y]&&ind[y]){
que.push(y);
break;
}
}
}
break;
}
bool ans=1;
for(int i=2;i<=n;++i)
if(cir[i]!=cir[i-1])
ans=0;
if(ans==0&&n%2==0){
ans=1;
for(int i=3;i<=n;++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: 7ms
memory: 26908kb
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: 44ms
memory: 26916kb
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 No No No No No No Yes No No No Yes No Yes 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 Yes No No No No No No No No No No No No No No No No N...
result:
wrong answer expected NO, found YES [19th token]