Approach hintTry it first, then revealHide
Each connected component needs exactly one bribed character, and its cheapest member is the best choice. Sum the minimum cost over all components found by DFS or BFS, using a 64-bit total.
Each connected component needs exactly one bribed character, and its cheapest member is the best choice. Sum the minimum cost over all components found by DFS or BFS, using a 64-bit total.