QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744423#7786. Graft and Transplantyld#WA 0ms3816kbC++20835b2024-11-13 21:52:422024-11-13 21:52:42

Judging History

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

  • [2024-11-13 21:52:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-11-13 21:52:42]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve()
{
    int n;
    cin>>n;
    if(n==2) {cout<<"Bob\n";return;}
    vector<int> deg(n+1);
    vector<int> e[n+1];
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int num=0;
    function<void(int,int)> dfs=[&](int u,int fa)
    {
        int flag=0;
        for(auto v:e[u])
        {
            if(v==fa) continue;
            flag=1;
            dfs(v,u);
        }
        if(flag && fa!=1 && u!=1) num++;
    };
    dfs(1,0);
    // cout<<num<<endl;
    if(num%2) cout<<"Alice\n";
    else cout<<"Bob\n";
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

4
1 2
2 3
3 4

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

4
1 2
1 3
1 4

output:

Bob

result:

ok "Bob"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

2
1 2

output:

Bob

result:

ok "Bob"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3
1 2
1 3

output:

Bob

result:

ok "Bob"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

input:

5
2 1
2 3
3 4
1 5

output:

Alice

result:

wrong answer 1st words differ - expected: 'Bob', found: 'Alice'