QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778536 | #6307. Chase Game 2 | liuwei# | WA | 1ms | 6244kb | C++14 | 932b | 2024-11-24 15:06:34 | 2024-11-24 15:06:34 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'