Matrix and graph

0

0 votes
Graph, Hard, Algorithms, Graph Representation
Problem

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 0n1, and to minimize (eEa[p[e.u]][p[e.v]])(eEb[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=(eEa[p[e.u]][p[e.v]])(eEb[p[e.u]][p[e.v]]). Then your score is Ansn4m21012.

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,,dn1 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

mn2

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

eEa[p[e.u][p[e.v]]=a[1][2]+a[1][0]=107+2107=3107

eEb[p[e.u][p[e.v]]=b[1][2]+b[1][0]=107+107=2107

Ans=61014

The score is 6101434221012=12150

Editor Image

?