Alice and Bob are playing a game on a graph. They have an undirected graph without self-loops and multiple edges. All vertices of the graph have degree equal to 22. The graph may consist of several components. Note that if such graph has nn vertices, it will have exactly nn edges.
Alice and Bob take turn. Alice goes first. In each turn, the player can choose kk (l≤k≤rl≤k≤r; l<rl<r) vertices that form a connected subgraph and erase these vertices from the graph, including all incident edges.
The player who can't make a step loses.
For example, suppose they are playing on the given graph with given l=2l=2 and r=3r=3:
A valid vertex set for Alice to choose at the first move is one of the following:
- {1,2}{1,2}
- {1,3}{1,3}
- {2,3}{2,3}
- {4,5}{4,5}
- {4,6}{4,6}
- {5,6}{5,6}
- {1,2,3}{1,2,3}
- {4,5,6}{4,5,6}
Suppose, Alice chooses subgraph {4,6}{4,6}.
Then a valid vertex set for Bob to choose at the first move is one of the following:
- {1,2}{1,2}
- {1,3}{1,3}
- {2,3}{2,3}
- {1,2,3}{1,2,3}
Suppose, Bob chooses subgraph {1,2,3}{1,2,3}.
Alice can't make a move, so she loses.
You are given a graph of size nn and integers ll and rr. Who will win if both Alice and Bob play optimally.
Input
The first line contains three integers nn, ll and rr (3≤n≤2⋅1053≤n≤2⋅105; 1≤l<r≤n1≤l<r≤n) — the number of vertices in the graph, and the constraints on the number of vertices Alice or Bob can choose in one move.
Next nn lines contains edges of the graph: one edge per line. The ii-th line contains two integers uiui and vivi (1≤ui,vi≤n1≤ui,vi≤n; ui≠viui≠vi) — description of the ii-th edge.
It's guaranteed that the degree of each vertex of the given graph is equal to 22.
Output
Print Alice (case-insensitive) if Alice wins, or Bob otherwise.
Examples
input
Copy
6 2 3 1 2 2 3 3 1 4 5 5 6 6 4
output
Copy
Bob
input
Copy
6 1 2 1 2 2 3 3 1 4 5 5 6 6 4
output
Copy
Bob
input
Copy
12 1 3 1 2 2 3 3 1 4 5 5 6 6 7 7 4 8 9 9 10 10 11 11 12 12 8
output
Copy
Alice
Note
In the first test the same input as in legend is shown.
In the second test the same graph as in legend is shown, but with l=1l=1 and r=2r=2.
我本来也想不出来,然后参考了一下大佬的代码
先看代码把:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#define int long long
int fa[200001],cnt[200001],n,l,r,s;
int getfa(int x)
{
if(x==fa[x]) return x;
return fa[x]=getfa(fa[x]);
}
void solve()
{
cin >> n >> l >> r;
for(int i=1;i<=n;++i) fa[i]=i;
for(int i=1,u,v;i<n;++i)
{
cin >> u >> v;
fa[getfa(u)]=getfa(v);
}
for(int i=1;i<=n;++i)
++cnt[getfa(i)];
for(int i=1;i<=n;++i)
if(cnt[i]>0&&cnt[i]<l+r)
s^=cnt[i]/l;
if(s!=0) cout << "Alice" << endl;
else cout << "Bob" << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
前面那些并查集就不用说了,讲一下后面博弈的部分
这大概就是一个sg函数加上尼姆博弈
第一个难点就是为什么是cnt[i]<l+r才适用呢
假设他l=3 r=5
假设他的环是11个让他减去3个不是先手必胜态吗
可惜他是一条直线 他取得点必须是连续的
bob只要在中间将他一分为二 要么alic不可操作 要么分成两条相同可操作性的直线 然后就学着Alice的操作照猫画猫最后不能操作的还是Alice
由尼姆博弈可以知道要使他们异或等于0
但是尼姆博弈从1开始取而我们从l开始于是环数除以l
看上面的sg图吧
6和7 的值都是2
也就是6和7都可以变成sg值为 0 1所以并没影响