QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375796#6830. Just Some Bad Memorywjh213WA 1ms6692kbC++141.8kb2024-04-03 16:01:372024-04-03 16:01:38

Judging History

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

  • [2024-04-03 16:01:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6692kb
  • [2024-04-03 16:01:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pr pair<int,int>
#define fi first
#define se second
int const MAX=1e5+10;
vector<int> V[MAX];
bool ji,ou;
int dep[MAX],fa[MAX];
bool fl[MAX];
set<pr> S;
void maketag(int now,int top){
	//cerr<<now<<" "<<top<<"\n";
	if(now==top)return ;
	if(S.count({now,fa[now]})){
		//cerr<<now<<" "<<top<<"\n";
		ou=true;
		return ;
	}
	S.insert({now,fa[now]});
	maketag(fa[now],top);
}
void dfs(int t1,int last){
	if(fl[t1]){
		int tp=dep[last]-dep[t1];
		if(tp<=0||tp==1)return;
		if(tp%2==1)ou=true;
		if(tp%2==0){
			ji=true;
			maketag(last,t1);
		}
		return;
	}
	fa[t1]=last;
	dep[t1]=dep[last]+1;
	fl[t1]=true;
	for(auto it:V[t1]){
		dfs(it,t1);
	}
	return;
}
int maxx=0;
void dfs2(int now,int last){
	maxx=max(maxx,dep[now]);
	if(fl[now])return;
	fl[now]=true;
	for(auto it:V[now]){
		//dep[it]=max(dep[it],dep[now]+1);
		if(fl[it])continue;
		dep[it]=dep[now]+1;
		dfs2(it,now);
	}
	return;
}
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	if(n<=3){
		cout<<-1;
		return 0;
	}
	if(m<=2){
		cout<<5-m;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(!fl[i])dfs(i,0);
	}
	//cerr<<ji<<" "<<ou<<"\n";
	if(ji&&ou){
		cout<<0;
		return 0;
	}
	bool qwq=false;
	for(int i=1;i<=n;i++){
		bitset<MAX> B;
		for(auto it:V[i])B[it]=1;
		for(auto it:V[i]){
			bitset<MAX> B2;
			for(auto it2:V[it])B2[it2]=1;
			bitset<MAX> B3=B2|B;
			//if(i==2&&it==3)cerr<<B.count()<<" "<<B2.count()<<" "<<B3.count()<<"\n";
			if(B.count()>=2&&B2.count()>=2&&B3.size()>=4)qwq=true;
			if(qwq)break;
		}
		if(qwq)break;
	}
	if(ji){
		//cerr<<maxx<<"\n";
		if(qwq)cout<<1;
		else cout<<2;
		return 0;
	}
	if(ou){
		cout<<1;
		return 0;
	}
	if(qwq)cout<<2;
	else cout<<3;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6008kb

input:

3 3
1 2
2 3
1 3

output:

-1

result:

ok "-1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5996kb

input:

4 0

output:

5

result:

ok "5"

Test #3:

score: 0
Accepted
time: 1ms
memory: 6512kb

input:

5 4
1 2
2 3
3 4
4 5

output:

2

result:

ok "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 6008kb

input:

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

output:

0

result:

ok "0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 6692kb

input:

4 4
1 2
2 3
3 4
4 1

output:

1

result:

ok "1"

Test #6:

score: 0
Accepted
time: 1ms
memory: 6044kb

input:

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

output:

0

result:

ok "0"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5972kb

input:

4 3
1 2
2 3
3 1

output:

1

result:

wrong answer 1st words differ - expected: '2', found: '1'