QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778470#6307. Chase Game 2liuwei#WA 1ms6292kbC++14959b2024-11-24 14:47:422024-11-24 14:47:43

Judging History

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

  • [2024-11-24 14:47:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6292kb
  • [2024-11-24 14:47:42]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6292kb

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

result:

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