#P6815. Sum of Triangle Contributions in a Graph

    ID: 20022 Type: Default 1000ms 256MiB

Sum of Triangle Contributions in a Graph

Sum of Triangle Contributions in a Graph

Given an undirected graph with (n) vertices and (m) edges, where each vertex (i) has an associated weight (a_i). A triangle in the graph is defined as a triple of vertices ((i, j, k)) (with (i < j < k)) such that each pair of these vertices is connected by an edge. The contribution of a triangle ((i, j, k)) is defined as (\max(a_i,,a_j,,a_k)).


Your task is to compute the sum of contributions of all triangles in the graph.

Note: The vertices are numbered from 1 to (n).

inputFormat

The first line contains two integers (n) and (m) — the number of vertices and the number of edges, respectively.

The second line contains (n) integers (a_1, a_2, \ldots, a_n) representing the weight of each vertex.

Each of the next (m) lines contains two integers (u) and (v) indicating an undirected edge between vertices (u) and (v>.

outputFormat

Output a single integer, the sum of contributions for all triangles in the graph.

sample

4 3
1 2 3 4
1 2
2 3
3 1
3