Edit: AC
In this problem, one needs to compute Minimum spanning tree w query times! As running MST on the full graph every time will surely lead to TLE, my idea is to only work with the MST I get after each query! But it's unexpected for me to get MLE! I've just taken two adjacency list for only 205 nodes and simple a 205 size array. How can it lead to MLE? Plz help!
The full problem description can be found here: 1123 — Trail Maintenance
Thanks in Advance
Try clearing memory by assigning null value to adjancency list variable and call System.gc() at the end of every test case.