QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235778 | #5307. Subgraph Isomorphism | ushg8877# | WA | 48ms | 9344kb | C++20 | 1.1kb | 2023-11-03 09:07:38 | 2023-11-03 09:07:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=1e5+5;
const int MOD=998244353;
int n,m,a[MAXN];
vector<int> edg[MAXN];
ll val[MAXN],hs[MAXN],d[MAXN],dep[MAXN];
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++) edg[i].clear(),hs[i]=1,dep[i]=0;
for(int i=1,u,v;i<=m;i++){
cin>>u>>v;
edg[u].push_back(v);
edg[v].push_back(u);
}
for(int i=1;i<=n;i++) d[i]=edg[i].size();
if(m==n-1){cout<<"YES"<<endl;return;}
if(m>n){cout<<"NO"<<endl;return;}
queue<int> q;
for(int i=1;i<=n;i++) if(d[i]==1) q.push(i);
while(!q.empty()){
int u=q.front();q.pop();
hs[u]=(hs[u]+val[dep[u]])%MOD;
// cout<<u<<' '<<hs[u]<<endl;
for(int v:edg[u]){
if(d[v]<=1) continue;
hs[v]=hs[v]*hs[u]%MOD;
dep[v]=max(dep[v],dep[u]);
if(--d[v]==1) q.push(v);
}
}
ll tot=-1;
for(int i=1;i<=n;i++) if(d[i]>=2){
if(tot==-1) tot=hs[i];
else if(tot!=hs[i]){cout<<"NO"<<endl;return;}
}
cout<<"YES"<<endl;
}
int main(){
ios::sync_with_stdio(false);
for(int i=0;i<MAXN;i++) val[i]=rnd()%MOD;
int _;cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9344kb
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: 48ms
memory: 8756kb
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 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 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 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 [39th token]