QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292947 | #6307. Chase Game 2 | zxzxzxq# | WA | 4ms | 3452kb | C++17 | 1.0kb | 2023-12-28 17:34:07 | 2023-12-28 17:34:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=200200;
int sz[maxn];
int deg[maxn],n;
int ans=0,total;
struct mmm{
int x,y;
}looker[maxn];
void solve()
{
cin>>n;
total=0;
ans=0;
for(int i=1;i<=n;i++) deg[i]=0,sz[i]=0;
for(int i=1;i<=n-1;i++)
{
cin>>looker[i].x>>looker[i].y;
deg[looker[i].x]++;
deg[looker[i].y]++;
}
int flag=0;
for(int i=1;i<=n;i++)
{
if(deg[looker[i].x]==1&°[looker[i].y]==1) flag=1;
if(deg[looker[i].x]==1) sz[looker[i].y]++,total++;
if(deg[looker[i].y]==1) sz[looker[i].x]++,total++;
}
for(int i=1;i<=n;i++)
{
if(deg[i]==n-1) flag=1;
if(sz[i]>total/2)
ans+=sz[i]*2-total;
}
if(flag) cout<<-1<<'\n';
else
{
int loooker=total-ans;
ans+=(loooker+1)/2;
cout<<ans<<'\n';
}
}
signed main()
{
ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
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:
ok 4 number(s): "-1 1 -1 2"
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3404kb
input:
10000 4 1 2 1 3 3 4 4 1 2 1 3 1 4 4 1 2 2 3 1 4 5 1 2 2 3 1 4 4 5 5 1 2 2 3 3 4 4 5 4 1 2 2 3 2 4 5 1 2 1 3 2 4 2 5 4 1 2 2 3 1 4 5 1 2 1 3 2 4 1 5 5 1 2 2 3 3 4 2 5 5 1 2 1 3 2 4 2 5 4 1 2 1 3 3 4 5 1 2 1 3 3 4 1 5 4 1 2 1 3 1 4 5 1 2 1 3 3 4 3 5 5 1 2 2 3 3 4 3 5 4 1 2 1 3 2 4 5 1 2 2 3 2 4 3 5 5 ...
output:
1 -1 1 1 1 -1 2 2 2 2 2 -1 2 -1 2 2 -1 2 2 -1 2 2 -1 2 2 2 2 -1 -1 1 2 1 -1 -1 1 2 -1 -1 -1 -1 -1 -1 2 2 2 1 -1 -1 -1 2 2 2 1 2 -1 2 -1 -1 2 -1 -1 -1 2 2 2 1 1 2 2 2 2 -1 2 2 -1 1 1 -1 2 -1 -1 1 2 2 2 1 -1 1 2 2 2 1 -1 -1 2 -1 1 -1 2 -1 2 2 2 1 -1 2 -1 2 -1 -1 2 -1 2 2 2 2 1 1 2 -1 2 1 2 2 1 -1 2 2 ...
result:
wrong answer 8th numbers differ - expected: '1', found: '2'