QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733610#5307. Subgraph IsomorphismFluoresceWA 2ms10032kbC++202.4kb2024-11-10 20:07:002024-11-10 20:07:00

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 20:07:00]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10032kb
  • [2024-11-10 20:07:00]
  • 提交

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],cyc[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);
				cyc[u]=1;//断边 
			}
			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]&&!cyc[u]){
			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;
	memset(cyc,0,n+3);
	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);
	PII p;
	for(int i=0;i<rs.size();++i){
		x=ahu(rs[i]);
		if(rs.size()&1){
			if(i==0)p.ft=x;
			else {
				if(x!=p.ft){
					cout<<"NO\n";return ;
				}
			}
		} else{
			if(i==0)p.ft=x;
			else if(i==1)p.sd=x;
			else{
				if(i&1){
					if(x!=p.sd){
						cout<<"NO\n";return ;
					}
				}else {
					if(x!=p.ft){
						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: 0
Wrong Answer
time: 2ms
memory: 10032kb

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
YES
YES

result:

wrong answer expected NO, found YES [3rd token]