QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764966 | #7786. Graft and Transplant | lei | WA | 3ms | 5764kb | C++20 | 1.4kb | 2024-11-20 11:23:44 | 2024-11-20 11:23:46 |
Judging History
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]==1||d[v]==1) continue;
else
{
d[u]+=(d[v]-1);
d[v]=1;
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);
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: 5764kb
input:
4 1 2 2 3 3 4
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
4 1 2 1 3 1 4
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 3ms
memory: 5688kb
input:
2 1 2
output:
Bob
result:
ok "Bob"
Test #4:
score: 0
Accepted
time: 2ms
memory: 5688kb
input:
3 1 2 1 3
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 3ms
memory: 5688kb
input:
5 2 1 2 3 3 4 1 5
output:
Bob
result:
ok "Bob"
Test #6:
score: 0
Accepted
time: 3ms
memory: 5628kb
input:
6 4 3 4 2 4 5 4 1 4 6
output:
Bob
result:
ok "Bob"
Test #7:
score: 0
Accepted
time: 3ms
memory: 5700kb
input:
7 2 4 4 1 1 5 5 3 3 7 7 6
output:
Bob
result:
ok "Bob"
Test #8:
score: -100
Wrong Answer
time: 3ms
memory: 5700kb
input:
8 2 3 3 1 3 6 7 6 6 5 7 8 6 4
output:
Alice
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Alice'