QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220758#6307. Chase Game 2kokosuki#WA 0ms6340kbC++14781b2023-10-20 19:47:122023-10-20 19:47:12

Judging History

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

  • [2023-10-20 19:47:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6340kb
  • [2023-10-20 19:47:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =1e5+10;
vector<int> v[N];
int cnt[N];
void sl()
{
	int n;
	cin>>n;
	memset(cnt,0,sizeof(cnt));
	vector<int> vv;
	for(int i=1;i<=n;i++)
	{
		v[i].clear();
	}
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
		
	}
	if(n<=3)
	{
		cout<<-1<<endl;
	}
	int sum=0;
	int maxx=0;
	for(int i=1;i<=n;i++)
	{
		if(v[i].size()==1)
		{
			cnt[v[i][0]]++;
			sum++;
			maxx=max(maxx,cnt[v[i][0]]);
		}
	}
	if(maxx==sum)
	{
		cout<<-1<<endl;
	}
	else if(maxx*2<sum)
	{
		cout<<(sum+1)/2<<endl;
	} 
	else cout<<maxx<<endl; 
	
}
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		sl();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 6340kb

input:

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

output:

-1
1
1
-1
2

result:

wrong answer 3rd numbers differ - expected: '-1', found: '1'