Given a graph G=(V,E) with n vertices and m edges, and two matrices A[n][n] and B[n][n]. You need to find a permutation p of 0…n−1, and to minimize (∑e∈Ea[p[e.u]][p[e.v]])⋅(∑e∈Eb[p[e.u]][p[e.v]]) (e.u and e.v are the two vertices of edge e).
Input
First line contains two integers, n and m.
The next n lines, each line contains n integers, the jth integer in the ith line is A[i-1][j-1].
The next n lines, each line contains n integers, the jth integer in the ith line is B[i-1][j-1].
The next m lines, each line contains two integers u and v, represent an edge in the graph.
Output
The permutation p.
Scoring
Let Ans=(∑e∈Ea[p[e.u]][p[e.v]])⋅(∑e∈Eb[p[e.u]][p[e.v]]). Then your score is Ans⋅n4m2⋅1012.
Data generation
There are 3 types of data.
1. n=256, a[i][j] and b[i][j] are randomly selected in [0,214], and the given graph is a tree. The tree is generated by randomly choosing a father between [0,i-1] for all vertices i between 1 and n-1, and then shuffle the vertices. There are 25 cases of this type.
2. n=64, a[i][j] and b[i][j] are randomly selected in [0,218]. There are 25 cases of this type.
3. n=256, a[i][j] and b[i][j] are randomly selected in [0,214]. There are 50 cases of this type.
The graph for type 2 and 3 is generated in this way:
First, for each test file, range [mind,maxd] is manually assigned. A sequence d0,d1,…,dn−1 will be drawn randomly independently from the uniform integer distribution over the range [mind,maxd]. Then the graph is generated using the expected_degree_graph function.
After the contest, data will be generated again with different seeds.
Constraints
m≤n2
∑e∈Ea[p[e.u][p[e.v]]=a[1][2]+a[1][0]=107+2⋅107=3⋅107
∑e∈Eb[p[e.u][p[e.v]]=b[1][2]+b[1][0]=107+107=2⋅107
Ans=6⋅1014
The score is 6⋅1014⋅3422⋅1012=12150