CF BUDDY
← Problems·

1991E · Coloring Game

1900 · constructive algorithms, dfs and similar, games

Problem: This is an interactive problem.

Consider an undirected connected graph consisting of nn vertices and mm edges. Each vertex can be colored with one of three colors: 11, 22, or 33. Initially, all vertices are uncolored.

Alice and Bob are playing a game consisting of nn rounds. In each round, the following two-step process happens:

  1. Alice chooses two different colors.
  2. Bob chooses an uncolored vertex and colors it with one of the two colors chosen by Alice.

Alice wins if there exists an edge connecting two vertices of the same color. Otherwise, Bob wins.

You are given the graph. Your task is to decide which player you wish to play as and win the game.

Input Format: Each test contains multiple test cases. The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn, mm (1n1041 \le n \le 10^4, n1mmin(n(n1)2,104)n - 1 \le m \le \min(\frac{n \cdot (n - 1)}{2}, 10^4)) — the number of vertices and the number of edges in the graph, respectively.

Each of the next mm lines of each test case contains two integers uiu_i, viv_i (1ui,vin1 \le u_i, v_i \le n) — the edges of the graph. It is guaranteed that the graph is connected and there are no multiple edges or self-loops.

It is guaranteed that the sum of nn and the sum of mm over all test cases does not exceed 10410^4.

Note: Note that the sample test cases are example games and do not necessarily represent the optimal strategy for both players.

In the first test case, you choose to play as Alice.

  1. Alice chooses two colors: 33 and 11. Bob chooses vertex 33 and colors it with color 11.
  2. Alice chooses two colors: 11 and 22. Bob chooses vertex 22 and colors it with color 22.
  3. Alice chooses two colors: 22 and 11. Bob chooses vertex 11 and colors it with color 11.

Alice wins because the edge (3,1)(3, 1) connects two vertices of the same color.

In the second test case, you choose to play as Bob.

  1. Alice chooses two colors: 22 and 33. Bob chooses vertex 11 and colors it with color 22.
  2. Alice chooses two colors: 11 and 22. Bob chooses vertex 22 and colors it with color 11.
  3. Alice chooses two colors: 22 and 11. Bob chooses vertex 44 and colors it with color 11.
  4. Alice chooses two colors: 33 and 11. Bob chooses vertex 33 and colors it with color 33.

Bob wins because there are no edges with vertices of the same color.

Sample Cases

Case 1

Input

2
3 3
1 2
2 3
3 1


3 1

2 2

1 1
4 4
1 2
2 3
3 4
4 1

2 3

1 2

2 1

3 1

Output

Alice
3 1

1 2

2 1






Bob

1 2

2 1

4 1

3 3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback