QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733446 | #5307. Subgraph Isomorphism | Fluoresce | WA | 41ms | 7928kb | C++20 | 2.1kb | 2024-11-10 19:04:52 | 2024-11-10 19:04:54 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define vec vector
#define pushk push_back
#define ump unordered_map
#define pl p<<1
#define pr p<<1|1
using namespace std;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9+7;
const ll inf = 1e18;
const ld eps = 1e-13;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy, _ = 1, __ = 1;
void bout(bool f) {
if (f)cout << "YES\n";
else cout << "NO\n";
}
ll n, m, k;
int h[N],e[M],ne[M],idx;
void link(int x,int y){
e[++idx]=y;
ne[idx]=h[x];
h[x]=idx;
}
vec<int> rs;
int rt;
bool f,st[N];
int pdfs(int u,int fa){
if(st[u]){//ring
rt=u;
f=1;
rs.clear();
return 1;//find
}
st[u]=1;
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
if((i^1)==fa)continue;//只判父向边,不判其他边
if(pdfs(v,i)){
if(f)rs.push_back(u);
if(u==rt)f=0;
st[u]=0;
return 1;
}
}
st[u]=0;
return 0;
}
map<vec<int>,int>id;
int idc;
int ahu(int u){
st[u]=1;
vec<int> tmp;
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
if(!st[v]){
tmp.push_back(ahu(v));
}
}
sort(tmp.begin(),tmp.end());
int &x=id[tmp];if(!x)x=++idc;
st[u]=0;
return x;
}
void ini() {
}
void solve() {
cin>>n>>m;
memset(h,-1,4*(n+3));idx=1;
int x,y,z;
for(int i=1;i<=m;++i){
cin>>x>>y;
link(x,y);
link(y,x);
}
if(m==n-1){
cout<<"YES\n";
return ;
}else if(m>n){
cout<<"NO\n";return ;
}
pdfs(1,0);
for(int i=0;i<rs.size();++i){
x=ahu(rs[i]);
if(i==0)y=x;
else{
if(y!=x){
cout<<"NO\n";return ;
}
}
}
cout<<"YES\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
streambuf *cinbp=cin.rdbuf(),*coutbp=cout.rdbuf();
ifstream fin("in.txt");
ofstream fout("out.txt");
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
#endif
cin >> _;
__ = _;
ini();
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7876kb
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: 41ms
memory: 7928kb
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]