QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212252#6830. Just Some Bad MemoryqzzyqWA 3ms8320kbC++141.9kb2023-10-13 13:43:382023-10-13 13:43:38

Judging History

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

  • [2023-10-13 13:43:38]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8320kb
  • [2023-10-13 13:43:38]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define maxn 200005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
void read(int &x){
    int f=1;x=0;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    x*=f;
}
namespace Debug{
	Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
int power(int x,int y=mod-2) {
	int sum=1;
	while (y) {
		if (y&1) sum=sum*x%mod;
		x=x*x%mod;y>>=1;
	}
	return sum;
}
vector<int>to[maxn];
int n,m,dfn[maxn],deep[maxn],fl1,fl2,dp[maxn],ans;
void dfs(int x,int pre) {
	dfn[x]=1;deep[x]=deep[pre]+1;
	int Max=0,Maxx=0;
	for (auto y:to[x]) if (y^pre) {
		if (!dfn[y]) {
			dfs(y,x);
			if (Max<=dp[y]) Maxx=Max,Max=dp[y];
			else if (Maxx<=dp[y]) Maxx=dp[y];
			dp[x]=max(dp[x],dp[y]+1);
		}
		else {
			if ((deep[y]-deep[x])%2) fl1=max(fl1,deep[y]-deep[x]+1);
			else fl2=max(fl2,deep[y]-deep[x]+1);
		}
	}
	ans=max(ans,Max+Maxx+1);
}
signed main(void){
//	freopen("1.in","r",stdin);
	int i,x,y;
	read(n);read(m);
	if (n<=3) return puts("-1"),0;
	for (i=1;i<=m;i++) {
		read(x),read(y);
		to[x].push_back(y);
		to[y].push_back(x);
	}
	for (i=1;i<=n;i++) if (!dfn[i]) dfs(i,0);
	if (fl1&&fl2) puts("0");
	else if (fl1) {
		if (fl1==3&&ans<=3) printf("2");
		else printf("1");
	}
	else if (fl2) {
		printf("1");
	}
	else printf("%d",max(4-ans,0)+2);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8048kb

input:

3 3
1 2
2 3
1 3

output:

-1

result:

ok "-1"

Test #2:

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

input:

4 0

output:

5

result:

ok "5"

Test #3:

score: 0
Accepted
time: 3ms
memory: 8276kb

input:

5 4
1 2
2 3
3 4
4 5

output:

2

result:

ok "2"

Test #4:

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

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: 2ms
memory: 8320kb

input:

4 4
1 2
2 3
3 4
4 1

output:

1

result:

ok "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 8188kb

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: 2ms
memory: 8244kb

input:

4 3
1 2
2 3
3 1

output:

1

result:

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