Judgement Day 2 solution codechef 2021
You are going to be born as a saint on a planet far from earth. The planet consists ofislands. Your job is to civilize the islands (not mandatorily all). Each island has its virtue level and you will get a follower from each island you visit.
At each island the virtue level of you and your followers will drop down to the minimum of your current virtue level and virtue level of that island. You and your followers will go to heaven if the sum of the final virtue level of all members in the group () is greater than . Find the maximum value of for which your group can go to heaven.
Assume initially you have infinite virtue level and it’s mandatory to visit at least one island. You can start at any island and stop at any island and you will visit all the islands along the path. You can’t visit an island more than once.
NOTE: There won’t be more than one path between two islands and Each island is connected to at max 2 islands.
Input: Judgement Day 2 solution codechef 2021
- The first line will contain number of islands and number of paths .
- The next line will contain N spaced integers , the virtue level of each island.
- The next m lines contains two integers and which describes a bi-directional path between the islands
Output: Judgement Day 2 solution codechef 2021
Output the maximum value of.
Constraints: Judgement Day 2 solution codechef 2021
- The islands are numbered from to
Sample Input 0: Judgement Day 2 solution codechef 2021
5 3 1 5 3 9 4 0 1 1 2 3 4
Sample Output 0: Judgement Day 2 solution codechef 2021
You can start and stop at island 4. If you start from island 3 and stop at island 4, your virtue level will be 2*min(9,4) = 8 (<9).
Sample Input 1:
6 4 5 4 3 6 2 1 4 1 1 2 2 0 0 5
Sample Output 1:
All the islands are connected in the following order 4<->1<->2<->0 <->5 If you start at island 0 virtue level of the group will be 5. If you move to island 2 from 0, the virtue level of the group will be. If you move to island 1 from island 0 (0->2->1), then your virtue level will be .
Program Code :
We don not promote cheating in any sense, so try you best and if you want solution you can check it after a day.
ALL THE BEST.