QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#681504 | #6307. Chase Game 2 | karito# | WA | 1ms | 3668kb | C++20 | 920b | 2024-10-27 09:46:21 | 2024-10-27 09:46:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> g[N];
vector<int> lev;
int dep[N];
void dfs(int x,int f){
int cnt=0;
dep[x]=dep[f]+1;
for(int y:g[x]){
if(y==f) continue;
dfs(y,x);
cnt++;
}
if(!cnt) lev.push_back(x);
}
void solve(){
int n;
cin>>n;
lev.clear();
for(int i=1;i<=n;i++){
g[i].clear();
dep[i]=0;
}
for(int i=1;i<n;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
dep[1]=1;
dfs(1,0);
int mx=0;
for(auto x:lev){
mx=max(mx,dep[x]);
}
if(mx<=3){
cout<<-1<<endl;
return;
}
else{
cout<<lev.size()<<endl;
return;
}
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
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: 0ms
memory: 3668kb
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 -1 -1 -1 2 -1 -1 -1 -1 -1 2 -1 2 -1 1 -1 -1 -1 -1 2 2 1 -1 -1 2 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 2 -1 -1 2 1 1 -1 -1 2 1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 2 -1 -1 2 2 -1 -1 1 1 1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1...
result:
wrong answer 1st numbers differ - expected: '1', found: '-1'