QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#681504#6307. Chase Game 2karito#WA 1ms3668kbC++20920b2024-10-27 09:46:212024-10-27 09:46:21

Judging History

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

  • [2024-10-27 09:46:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3668kb
  • [2024-10-27 09:46:21]
  • 提交

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'