Battle of Legends solution codechef
Arceus, the creator of the Pokémon world is very angry at humanity for what they did to Arceus in the past. Arceus is attacking to destroy the humanity. But the Legendary Trio of Dialga, Palkia and Giratina came to rescue the humanity. They are trying to battle Arceus with their full power. But Arceus is too powerful. So Dialga with its power over Time, sends Ash and his friends to past to change the past mistakes done by humanity. They have to complete the task given below to obtain the Jewel of Life and calm down Arceus by offering the Jewel.
Given a tree withvertices. Where each vertex has a character assigned to it. You have to answer queries. For each query you are given a starting vertex and length of the string to be found. String is formed by choosing a simple path starting at given vertex and appending the characters on vertices from start to end. Also the string must be the lexicographically smallest string possible. You have to print the encoding of the this string .
where,= 31 and for is a mapping from character to integer such that, = 1, = 2, …, = 26.
Input: Battle of Legends solution codechef
- First line will contain , number of test-cases. Then the test-cases follow.
- , number of vertices and number of queries.
- space separated characters for each vertex from to .
- Next – lines contain two integers and , showing there is an edge.
- Next lines contain two integers and . is the starting vertex and is the length of the string.
Output: Battle of Legends solution codechef
For each query, print the encoding of the lexicographically smallest string of length d and starting vertex u.
Constraints Battle of Legends solution codechef
- For each query of type ,
Sample Input: Battle of Legends solution codechef
1 4 2 a b c d 1 2 2 3 2 4 3 3 1 4
Query 1 : There are two ways. One is- - and other is - - . Strings formed by respective paths are cba and cbd. cba is lexicographically small than cbd. Hence encoding(cba) = 1026. Query 2 : There is no path of size 4 starting from 1. Hence answer is -1.
Codechef is an platform built to programmers compete against others in the community and to improve their knowledge by facing various challenges. Challenges are categorised on the basis of their difficulty level , if your rating is above 2000 you are in top tier i.e, Division 3 and if your rating is between 2000 and 1600 you will be in tier 2 i.e, Division 3 and if your rating is below that you will be in lowest tier i.e, Division 3. You can improve your rating by successful submission with minimum penalty.
- Game of Primes solution codechef
- Books and Friends solution codechef
- Run It Back solution codechef
- Buy Masks solution codechef
- How I Met Your Mother solution codechef
Also Read : Neenade Naa song lyrics with English Translation