QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764936#7786. Graft and TransplantleiWA 3ms5716kbC++201.5kb2024-11-20 11:16:232024-11-20 11:16:23

Judging History

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

  • [2024-11-20 11:16:23]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5716kb
  • [2024-11-20 11:16:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define PII pair<long long ,long long>
#define int long long
const int N = 2e6 + 10,MOD=1004535809,B=13331,inf=1e18,mod=998244353;
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')  x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write( int x ) {
    if ( x < 0 ) putchar ('-'), x = -x;
    if ( x > 9 ) write ( x / 10 ); putchar ( x % 10 | 48 );
}
int n,m,d[N];
vector<int>e[N];
vector<PII>a;
void lei()
{
    n=read(); 
    for(int i=1;i<n;i++)
    {
        int u=read(),v=read();
        e[u].push_back(v);
        e[v].push_back(u);
        a.push_back({u,v});
        d[u]++,d[v]++;
    }
    int ans=0;
    while(1)
    {
        int f=0;
        for(auto [u,v]:a)
        {
            if(!d[u]||!d[v]) continue;
            else
            {
                d[u]+=d[v];
                d[v]=0;
                f=1;
                ans^=1;
            }
        }
        if(!f) break;
    }
    if(!ans) cout<<"Alice";
    else cout<<"Bob";
}
signed main()
{
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(0);
//    std::cout.tie(0);

    // freopen("in.txt", "rt", stdin);
    // freopen("out.txt", "wt", stdout);
    int Tao=1;
   // Tao=read();
    while(Tao--)     lei();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5636kb

input:

4
1 2
2 3
3 4

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 3ms
memory: 5632kb

input:

4
1 2
1 3
1 4

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

2
1 2

output:

Bob

result:

ok "Bob"

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 5676kb

input:

3
1 2
1 3

output:

Alice

result:

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