QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630341 | #5307. Subgraph Isomorphism | lzx2017 | WA | 39ms | 9784kb | C++20 | 2.0kb | 2024-10-11 18:01:57 | 2024-10-11 18:01:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int i,j,n,m,k,l,x,y,t,vis[N],bz[N],dl[N],yes,ha[N],kk;
vector<int> G[N];
stack<int> dq;
void dfs(int x,int father)
{
vis[x]=1;
for(auto v:G[x]) if(v!=father){
if(yes) return;
if(!vis[v]){
dq.push(v);
dfs(v,x);
if(yes) return;
if(dq.size()) dq.pop();
} else {
while(dq.top()!=v){
bz[dq.top()]=1;
dl[++dl[0]]=dq.top();
dq.pop();
}
bz[v]=1;
dl[++dl[0]]=v;
dq.pop();
yes=1;
return;
}
}
}
void dfs1(int x,int father){
ha[x]=1992579;
for(auto v:G[x]) if(v!=father&&!bz[v]){
dfs1(v,x);
ha[x]=(ha[x]+1145147)^ha[v];
}
}
void solve()
{
kk++;
cin>>n>>m;
for(int i=1;i<=n;i++){
vis[i]=bz[i]=0;G[i].clear();ha[i]=0;
}
for(int i=1;i<=m;i++)
{
cin>>x>>y;
if(kk==19) cout<<x<<"|"<<y<<"|";
G[x].push_back(y);
G[y].push_back(x);
}
if(m==n-1) cout<<"YES"<<endl;
else if(m>n) cout<<"NO"<<endl;
else{
while(dq.size()) dq.pop();
dq.push(1);dl[0]=0;yes=0;
dfs(1,0);
for(int i=1;i<=dl[0];i++) dfs1(dl[i],0);
if(dl[0]%2==1){
for(int i=1;i<dl[0];i++) if(ha[dl[i]]!=ha[dl[i+1]]){
cout<<"NO"<<endl;
return;
}
}
else {
for(int i=1;i<dl[0]-1;i+=2) if(ha[dl[i]]!=ha[dl[i+2]]){
cout<<"NO"<<endl;
return;
}
for(int i=2;i<dl[0]-1;i+=2) if(ha[dl[i]]!=ha[dl[i+2]]){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
}
}
signed main()
{
// freopen("1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9784kb
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: 39ms
memory: 9708kb
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 1|3|1|5|2|4|2|5|3|5|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 NO YES NO NO 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 N...
result:
wrong output format YES or NO expected, but 1|3|1|5|2|4|2|5|3|5|YES found [19th token]