Table of Contents

# Gold Mining solution codechef

Chef has decided to go to a gold mine along with NN of his friends (thus, total N+1N+1 people including Chef go to the gold mine).

The gold mine contains a total of XX kg of gold. Every person has the capacity of carrying up atmostatmost YY kg of gold.

Will Chef and his friends together be able to carry up all the gold from the gold mine assuming that they can go to the mine exactly once.

## Input Format Gold Mining solution codechef

- First line will contain TT, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, three integers N,X,YN,X,Y.

### Output Format Gold Mining solution codechef

For each testcase, output `"YES"`

if you and your friends can carry all the gold, otherwise output `"NO"`

.

You may print each character of the string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

## Constraints Gold Mining solution codechef

- 1≤T≤10001≤T≤1000
- 1≤N,X,Y≤10001≤N,X,Y≤1000

### Sample Input 1 Gold Mining solution codechef

```
3
2 10 3
2 10 4
1 5 10
```

### Sample Output 1 Gold Mining solution codechef

```
NO
YES
YES
```

## Explanation Gold Mining solution codechef

**Test Case 11:** You along with your friends can only carry a maximum of 9(3×3)9(3×3) kg of gold.

**Test Case 22:** It is possible to carry all the gold from the mine. You can carry 44 kg of gold and your both friends carry 33 kg of gold each, thus carrying the whole 1010 kg of gold.

## Gold Mining solution codechef

You are given an undirected tree having NN nodes. The color of each node is either Black or White.

In one step, you can choose a node uu, toggle the color of the chosen node uu, as well as toggle the colors of all the nodes vv, such that {u,v}{u,v} is an edge in the tree.

Can you find out the minimum number of steps required to make the color of all the nodes black?

**Note:** Since the input is large, prefer using fast input methods.

### Input Format Gold Mining solution codechef

- The first line of input contains a single integer TT, denoting the number of test cases. The description of the TT test cases follows.
- The first line of each test case contains a single integer NN.
- The second line of each test case contains NN space separated integers A1,A2,...,ANA1,A2,…,AN. AiAi = 0 represents that the initial color of the ithith node is black. AiAi = 1 represents that the initial color of the ithith node is white.
- The following N−1N−1 lines contain two space-separated integers xx and yy, which denotes that there is an edge between nodes xx and yy.

### Output Format Gold Mining solution codechef

For each test case, output in a single line the minimum number of steps required to make the color of all the nodes black.

Output −1−1 if it is impossible to make the color of all the nodes black.

## Constraints Gold Mining solution codechef

- 1≤T≤5⋅1041≤T≤5⋅104
- 1≤N≤1051≤N≤105
- 0≤Ai≤10≤Ai≤1
- 1≤x,y≤N1≤x,y≤N
- The sum of NN over all test cases does not exceed 5⋅1055⋅105

### Sample Input 1 Gold Mining solution codechef

```
3
3
0 0 0
1 2
1 3
3
1 1 1
1 2
1 3
3
0 1 0
1 2
1 3
```

### Sample Output 1 Gold Mining solution codechef

```
0
1
2
```

## Explanation Gold Mining solution codechef

**Test Case 11:** All the nodes are already black, so we do not need to do anything.

**Test Case 22:** All the nodes are white. If we choose node 11 in the first step, all the nodes will become black. Hence, only 11 step is required to make all the nodes black.

**Test Case 33:** Choose node 33 in the first step. This will make all the nodes white. Choose node 11 in the second step. This will make all the nodes black.