Alternating Diameter Codechef Solution | May CHALLENGE

Codechef
Share:

Alternating Diameter Codechef Solution

Chef stumbled upon BB black nodes and WW white nodes and now wants to construct a tree using them.

Chef is bamboozled by the total number of trees that can be constructed using these nodes. To reduce this count, Chef considered only those trees which have at least one diameter that has alternating colors i.e. a black node is followed by a white node and a white node is followed by a black node.

Help Chef in finding out the tree with the minimum possible diameter among all the trees that satisfies the above condition. If no tree satisfies the above conditions, print −1−1. If multiple trees satisfies the above condition, print any.

Input Format

  • The first line contains a single integer TT – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two space separated integers B,WB,W representing the number of black and white nodes respectively.

Output Format

  • If a tree can be constructed that fulfils all the requirements then
    • In the first line, output a string of length B+WB+W in which the ithith character (1-based indexing) is either W or B denoting the colour of the ithith node as black or white respectively.
    • In the following B+W−1B+W−1 lines, output two integers UU and VV denoting an edge between UthUth and VthVth node.
  • If no tree fulfils the requirements print -1 in a single line.

Constraints

  • 1≤T≤1001≤T≤100
  • 0≤B,W≤10000≤B,W≤1000
  • 1≤B+W≤10001≤B+W≤1000

Sample Input 1 

3
1 1
0 2
1 2

Sample Output 1 

WB
2 1
-1
WBW
1 2
2 3

Explanation

Test case 11: The tree has only one path between the nodes 11 and 22 which is the diameter and also alternating in color. The checker will handle multiple possible answers so you can also swap the colors of the node to achieve the same result.

Test case 22: There is only one tree possible and its diameter would consist of all white nodes only. Therefore there is no tree which satisfies the given conditions.

Alternating Diameter Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x