QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778536#6307. Chase Game 2liuwei#WA 1ms6244kbC++14932b2024-11-24 15:06:342024-11-24 15:06:34

Judging History

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

  • [2024-11-24 15:06:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6244kb
  • [2024-11-24 15:06:34]
  • 提交

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;
		for(auto v:E[i]){
			if(E[v].size()==1){
				cnt++;
			}
		}
		if(cnt){
			p++;
			mx=max(mx,cnt);
			al+=cnt;
		}
	}
	if(p==1){
		puts("-1");
	}
	else if(mx<=al/2){
		cout<<ceil(1.0*al/2.0)<<endl;//可以两两匹配 
	}
	else{
	cout<<mx<<endl;//cnt可以匹配掉 
	}
}


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: 1ms
memory: 6244kb

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'