QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607423 | #5307. Subgraph Isomorphism | 999# | WA | 54ms | 22072kb | C++14 | 2.0kb | 2024-10-03 14:54:40 | 2024-10-03 14:54:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define M 300005
#define P1 19260817
#define P2 1000000007
#define K1 13448
#define K2 3213458
int n,m,deg[M],sk[M],mk[M],pw1[M],pw2[M];
struct hh{
int hs1,hs2,sz;
hh operator+(hh x)const{
hh a;
a.hs1=(1ll*hs1*pw1[x.sz]+x.hs1)%P1;
a.hs2=(1ll*hs2*pw2[x.sz]+x.hs2)%P2;
a.sz=sz+x.sz;
return a;
}
bool operator!=(hh x)const{
return hs1!=x.hs1||hs2!=x.hs2||sz!=x.sz;
}
bool operator<(hh x)const{
if(hs1==x.hs1)return hs2<x.hs2;
return hs1<x.hs1;
}
}dp[M],now,ac[M],fk[M];
vector<int>d[M];
void init(){
for(int i=1;i<=n;++i)deg[i]=0,d[i].clear();
}
void dfs(int x,int f){
for(int i=0;i<(int)d[x].size();++i){
int v=d[x][i];
if(mk[v]||v==f)continue;
dfs(v,x);
}
int cnt=0;
for(int i=0;i<(int)d[x].size();++i){
int v=d[x][i];
if(mk[v]||v==f)continue;
ac[++cnt]=dp[v];
}
sort(ac+1,ac+cnt+1);
dp[x]=(hh){3,3,1};
for(int i=1;i<=cnt;++i)dp[x]=dp[x]+ac[i];
dp[x]=dp[x]+(hh){2,2,1};
}
void solve(){
init();
scanf("%d%d",&n,&m);
for(int i=1,x,y;i<=m;++i){
scanf("%d%d",&x,&y);
d[x].push_back(y);
d[y].push_back(x);
deg[x]++;deg[y]++;
}
if(m>n){
puts("NO");
return;
}
if(m==n-1){
puts("YES");
return;
}
int cnt=0;
for(int i=1;i<=n;++i)if(deg[i]==1)sk[++cnt]=i;
int l=1,r=0;
while(l<=r){
int p=sk[l++];
for(int i=0;i<(int)d[p].size();++i){
int v=d[p][i];
deg[v]--;
if(deg[v]==1)sk[++r]=v;
}
}
for(int i=1;i<=n;++i)mk[i]=deg[i]>=2;
int sz=0;
for(int i=1;i<=n;++i)if(mk[i]){
dfs(i,0);
fk[++sz]=dp[i];
}
for(int i=2;i<=sz;++i){
if(sk[i]!=sk[1]){
int f=sz&1;
for(int j=1;j+2<=sz&&!f;j+=2){
f|=(fk[j]!=fk[j+2]);
f|=(fk[j+1]!=fk[j+3]);
}
if(f){
puts("NO");
return;
}
break;
}
}
puts("YES");
}
int main(){
pw1[0]=pw2[0]=1;
for(int i=1;i<M;++i)pw1[i]=1ll*K1*pw1[i-1]%P1,pw2[i]=1ll*K2*pw2[i-1]%P2;
int t;
scanf("%d",&t);
while(t--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 22072kb
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: 54ms
memory: 21912kb
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 NO NO NO NO NO NO NO NO NO NO NO NO YES YES NO YES YES NO NO NO NO NO NO NO NO NO YES YES NO NO YES YES NO NO NO 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 NO ...
result:
wrong answer expected YES, found NO [23rd token]