QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301949#6307. Chase Game 2USTC_fish_touching_team#WA 0ms1620kbC++14591b2024-01-10 14:45:532024-01-10 14:45:53

Judging History

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

  • [2024-01-10 14:45:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1620kb
  • [2024-01-10 14:45:53]
  • 提交

answer

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int T,n,du[N],t[N],con[N];
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			t[i]=du[i]=0;
		}
		for(int i=1,u,v;i<n;i++){
			scanf("%d%d",&u,&v);
			du[u]++;du[v]++;
			con[u]=v;
			con[v]=u;
		}
		int sum=0;
		for(int i=1;i<=n;i++){
			if(du[i]==1){
				t[con[i]]++;
				sum++;
			}
		}
		sort(t+1,t+n+1);
		if(t[n]==sum){
			printf("-1\n");
		}else if(t[n]*2<=sum){
			printf("%d\n",(sum-1)/2+1);
		}else{
			printf("%d\n",t[n]);
		}
	}
}

详细

Test #1:

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

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
2

result:

wrong answer 1st numbers differ - expected: '-1', found: '1'