QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695600 | #5307. Subgraph Isomorphism | Golem__ | ML | 8ms | 14108kb | C++17 | 4.2kb | 2024-10-31 20:25:10 | 2024-10-31 20:25:11 |
Judging History
answer
#include<random>
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<climits>
// #define NDEBUG
#include<cassert>
#include<cstring>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include<vector>
// #define LL __int128
#define LL long long
#define ULL unsigned LL
#define uint unsigned int
// #define int LL
// #define double long double
#define mkp make_pair
#define par pair<int,int>
#define epb emplace_back
#define psb push_back
#define f(x) ((x).first)
#define s(x) ((x).second)
using namespace std;
#define Lbt(x) ((x)&(-(x)))
#define Swap(x,y) (x^=y^=x^=y)
const int Mxxx=1e5;
inline char gc()
{
// return getchar();
static char buf[Mxxx],*p1=buf,*p2=buf;
return (p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxxx,stdin),p1==p2))?EOF:*p1++;
}
inline char pc(char ch,bool fl=false)
{
// return fl?0:putchar(ch),0;
static char buf[Mxxx],*p1=buf,*p2=buf+Mxxx;
return (fl||((*p1++=ch)&&p1==p2))&&(fwrite(buf,1,p1-buf,stdout),p1=buf),0;
}
#define output pc('!',true)
inline int read()
{
char ch=gc();
int gans=0,gflag=0;
for(;ch<'0'||'9'<ch;ch=gc())gflag|=(ch=='-');
for(;'0'<=ch&&ch<='9';ch=gc())gans=(gans<<1)+(gans<<3)+(ch^48);
return gflag?-gans:gans;
}
template<typename T>
inline char read(T&gans)
{
char ch=gc();
int gflag=0;gans=0;
for(;ch<'0'||'9'<ch;ch=gc())gflag|=(ch=='-');
for(;'0'<=ch&&ch<='9';ch=gc())gans=(gans<<1)+(gans<<3)+(ch^48);
return gans=gflag?-gans:gans,ch;
}
template<typename T>
inline void write(T x)
{
if(x>9)write(x/10);
pc(x%10^48);
}
template<typename T>
inline void writenum(T x,char ch)
{
if(x<0)x=-x,pc('-');
write(x),pc(ch);
}
inline void writechar(char x,char ch)
{
pc(x),pc(ch);
}
template<typename T>
inline T Max(T x,T y)
{
return x>y?x:y;
}
template<typename T>
inline T Min(T x,T y)
{
return x<y?x:y;
}
template<typename T>
inline T Abs(T x)
{
return x<0?-x:x;
}
template<typename T>
inline void ckmx(T&x,T y)
{
x=Max(x,y);
}
template<typename T>
inline void ckmn(T&x,T y)
{
x=Min(x,y);
}
const int Mx=1e5;
int TT,n,m,cnt,h[Mx+5],nxt[(Mx<<1)+5],tto[(Mx<<1)+5];
inline void ade(int x,int y)
{
nxt[++cnt]=h[x];
tto[h[x]=cnt]=y;
}
inline void Ade(int x,int y)
{
ade(x,y);ade(y,x);
}
int onc[Mx+5],vs[Mx+5];
int top,stk[Mx+5];
inline int DFS(int x,int y)
{
int i,to;
assert(!vs[x]);
vs[x]=1;
for(i=h[x];i;i=nxt[i])if((to=tto[i])^y)
{
if(vs[to])return stk[++top]=x,onc[x]=1,to;
int k=DFS(to,x);
if(k)return stk[++top]=x,onc[x]=1,x==k?0:k;
}
return 0;
}
const int M=2e6;
int tot,pri[M+5],vst[M+5];
ULL F[Mx+5];int sz[Mx+5];
inline void Slv(int x,int y)
{
int i,to;
F[x]=sz[x]=1;
for(i=h[x];i;i=nxt[i])if((to=tto[i])^x&&!onc[to])
{
Slv(to,x);
F[x]+=F[to]*pri[sz[to]];
sz[x]+=sz[to];
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("_.in","r",stdin);
// freopen("_.out","w",stdout);
#endif
int i,j,f;
for(i=2;i<=M;i++)
{
if(!vst[i])vst[i]=pri[++tot]=i;
for(j=1;j<=tot;j++)
{
if(pri[j]*i>M)break;
vst[pri[j]*i]=pri[j];
if(pri[j]==vst[i])break;
}
}
for(TT=read();TT;TT--)
{
n=read();m=read();
// cout<<"???\n";
if(m==n-1){for(i=1;i<=m;i++)read(),read();puts("YES");continue;}
if(m>n){for(i=1;i<=m;i++)read(),read();puts("NO");continue;}
assert(m==n);
cnt=0;for(i=1;i<=n;i++)h[i]=onc[i]=vs[i]=0;
for(i=1;i<=m;i++)Ade(read(),read());
top=0;assert(!DFS(1,0));
for(i=1;i<=top;i++)Slv(stk[i],0);
assert(top>=3);
// cout<<"HERE! Ck:"<<top<<"\n";
f=1;for(i=1;i<top;i++)f&=F[stk[i]]==F[stk[i+1]];
if(f){puts("YES");continue;}
f=!(top&1);for(i=1;i<=top-2;i++)f&=F[stk[i]]==F[stk[i+2]];
for(i=2;i<=top-2;i++)f&=F[stk[i]]==F[stk[i+2]];
if(f){puts("YES");continue;}
puts("NO");
}
return output;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 14108kb
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
Memory Limit Exceeded
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 ...