Editorial for TLE '16 Contest 1 P4 - Microwaves Again!


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

For 15% of the points, choose all combinations of 3 nodes, find all nodes within a distance of 1 from these 3 nodes, sum up all microwave values, and output the maximum sum found.

For an additional 35% of the points, we can use a BFS from each node in order to get the distance between any two nodes. Next, we can use a 2-D boolean array or N bitsets to keep track of whether a node is within a distance of K from another node. We then choose all combinations of 3 nodes, use the boolean array/bitset to find all nodes within a distance of K from these 3 nodes, sum up all microwave values, and output the maximum sum found.

For the remaining 50%, we can replace the BFS with Dijkstra or Floyd-Warshall and repeat the same bitmask procedure.

For all cases, ensure that the brute force has a low constant factor so that you will not exceed the time limit.

Time complexity: \mathcal{O}(N^4)


Comments

There are no comments at the moment.