QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#165567 | #6307. Chase Game 2 | 8xin | WA | 4ms | 3572kb | C++14 | 1.7kb | 2023-09-05 19:22:14 | 2023-09-05 19:22:14 |
Judging History
answer
// #include<iostream>
// #include<cstdio>
// #include<algorithm>
// #include<cstring>
// #include<cmath>
// #include<vector>
// #include<queue>
// #include<map>
// #include<unordered_map>
// #include<bitset>
// #include<set>
// #include<stack>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 0x3f3f3f3f
#define endl "\n"
#define pi acos(-1)
#define eps 1e-9
const ll mod=1e9+7;
ll qpow(ll base,ll power){
ll res=1;
while(power>0){
if(power&1) res=base*res%mod;
power>>=1;
base=base*base%mod;
}
return res;
}
ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
double dis(double x,double y,double x1,double y1){
return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
ll dis1(ll x,ll y,ll z,ll x1,ll y1,ll z1){
return (x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1);
}
double chaji(double x1,double x2,double y1,double y2){
return x1*y2-x2*y1;
}
const int N=1e6+10;
int in[N];
void solve() {
int n;
cin >> n;
for(int i=1;i<=n;i++) in[i]=0;
int x,y;
for(int i=1;i<n;i++){
cin >> x >> y;
in[x]++;
in[y]++;
}
if(n==2){
cout << -1 << endl;
return;
}
int cnt=0;
for(int i=1;i<=n;i++){
if(in[i]==1) cnt++;
}
if(cnt==n-1){
cout << -1 << endl;
return;
}
cout << cnt-1 << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t=1;
cin >> t;
//scanf("%d",&t);
while(t--){
//cout << "Case #" << ++cnt << ": ";
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: 0
Accepted
time: 4ms
memory: 3572kb
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 1 2 2 2 1 2 -1 2 2 1 2 2 1 1 1 -1 2 2 2 1 -1 1 1 2 1 1 -1 1 2 1 1 1 -1 1 1 2 2 2 1 1 1 -1 1 2 1 1 2 1 2 1 1 2 -1 -1 -1 2 2 2 1 1 1 2 2 2 -1 1 2 -1 1 1 -1 2 -1 -1 1 2 2 2 1 1 1 1 1 1 1 1 1 2 -1 1 1 2 -1 2 1 1 1 -1 2 -1 1 -1 -1 2 -1 2 1 2 2 1 1 1 1 2 1 1 1 1 -1 2 1 2 1 1 1 1 1 1 1 2 -1...
result:
ok 10000 numbers
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 3352kb
input:
10000 9 1 2 2 3 3 4 4 5 1 6 6 7 5 8 7 9 9 1 2 2 3 2 4 1 5 2 6 4 7 6 8 1 9 9 1 2 2 3 1 4 4 5 5 6 4 7 2 8 1 9 10 1 2 2 3 1 4 3 5 3 6 2 7 6 8 6 9 6 10 10 1 2 1 3 3 4 2 5 1 6 5 7 4 8 2 9 7 10 10 1 2 2 3 2 4 1 5 3 6 6 7 5 8 4 9 9 10 9 1 2 2 3 2 4 1 5 3 6 2 7 1 8 2 9 9 1 2 1 3 2 4 1 5 3 6 3 7 7 8 8 9 10 1...
output:
1 4 4 5 3 2 5 3 4 3 4 3 4 3 4 4 4 3 4 3 5 3 4 4 3 3 4 5 4 5 4 4 3 5 4 5 5 4 5 4 3 4 4 4 4 5 2 5 4 4 4 5 4 2 5 2 4 3 3 4 4 6 4 5 4 4 3 3 4 2 3 3 5 4 3 4 5 3 5 4 4 5 3 5 3 3 4 5 5 4 3 4 4 3 4 5 4 4 4 3 4 3 3 5 5 4 4 2 3 5 3 4 6 3 6 4 2 4 4 3 5 3 4 5 4 4 3 2 5 5 4 3 4 4 4 4 5 4 3 5 4 3 3 6 4 5 4 4 3 4 ...
result:
wrong answer 2nd numbers differ - expected: '3', found: '4'