QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733478#5307. Subgraph IsomorphismFluoresceWA 38ms9832kbC++202.2kb2024-11-10 19:17:102024-11-10 19:17:11

Judging History

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

  • [2024-11-10 19:17:11]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:9832kb
  • [2024-11-10 19:17:10]
  • 提交

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;
	if(__-_==39)cout<<n<<' '<<m<<'\n';
	for(int i=1;i<=m;++i){
		cin>>x>>y;
		link(x,y);
		link(y,x);
		if(__-_==39){
			cout<<x<<' '<<y<<'\n';
		}
	}
	if(__>100){
		return ;
	}
	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: 1ms
memory: 7828kb

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: 38ms
memory: 9832kb

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:

6 6
1 5
1 6
2 5
2 6
3 5
4 6

result:

wrong output format YES or NO expected, but 6 found [1st token]