QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778472#6307. Chase Game 2liuwei#WA 0ms6204kbC++14961b2024-11-24 14:48:082024-11-24 14:48:09

Judging History

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

  • [2024-11-24 14:48:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6204kb
  • [2024-11-24 14:48:08]
  • 提交

answer

#include<bits/stdc++.h>
 
using namespace std;

#define rep(i, a, b) for(int i = a;i <= b;i++)
#define pre(i, a, b) for(int i = a;i >= b;i--)
#define pb push_back
const int N=1e5+5;
vector<int>E[N];
void solve() {
    int n;
    cin >> n;rep(i,1,n)E[i].clear();
	rep(i,1,n-1){
		int u,v;cin>>u>>v;E[u].pb(v);E[v].pb(u);
	}
	if(n==2){
		puts("-1");
		return;
	}
	int rt=0;
	int mx=0,al=0,p=0;
	rep(i,1,n)if(E[i].size()>1){
		int cnt=0;
		p++;
		for(auto v:E[i]){
			if(E[v].size()==1){
				cnt++;
			}
		}
		if(cnt){
			mx=max(mx,cnt);
			al+=cnt;
		}
	}
	if(p==1){
		puts("-1");
	}
	else if(mx<=al/2){
		cout<<ceil(1.0*al/2)<<endl;
	}
	else{
	int cnt=min(mx,al-mx);//cout<<mx<<" "<<al<<" "<<cnt<<endl;
	
	cout<<(mx-cnt)+cnt<<endl;
	}
}


int main() {
 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin>> t ;


    while (t--) {
        solve();
    }


    return 0;
}

詳細信息

Test #1:

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

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
2
-1
-1

result:

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