2≤N≤105,1≤cv≤103。
The next N lines each describe a vertex. Line v+1v+1 contains five space-separated integers cv,pv,1,pv,2,pv,3,pv,4.
It is guaranteed that for each v pv,1,pv,2,pv,3,pv,4 are all distinct, and that every portal appears in the adjacency lists of exactly two vertices.
5
10 1 4 8 9
11 1 2 5 6
12 9 10 2 3
3 4 3 6 7
15 10 8 7 5
13
It suffices to permute the adjacency lists of vertices 1 and 4. This requires a total of c1+c4=13 moonies. We can let p1=[1,9,4,8] and p4=[7,4,6,3].