HackerRank/Graph Theory/Synchronous Shopping

Problem Summary

Given a map with N shopping centers and M bidirectional roads. Each road connects two distinct shopping centers and has a travel time. There are K different kinds of fish sold in these centers, and each center may have different kinds of fish.

Two cats travel from center 1 to center N, and they want to collectively purchase all K types of fish in a minimal amount of time. Any purchase costs no time. Their paths are not necessarily the same. The total shopping time is the maximum of two cats’ shopping times. Find the minimal total shopping time.
(2 ≤ N ≤ 1000 , 1 ≤ M ≤ 2000 , 0 ≤ K ≤ 10)

Read More

HackerRank/Algorithms/Graph Theory/The Story of a Tree

Problem Summary

Alice and Bob play a game.

Given a tree with N nodes, two integers G and K, and G guesses (u1,v1),…,(ug,vg). (1<=N,G,K<=100000)

(ui,vi) means Alice guesses that ui is the parent of vi.

When a node of the tree is randomly selected (with equal probability) to be root by Bob, and Alice does not know, find the probability that the number of right guesses is greater than or equal to K.

Read More