#P7146. [THUPC 2021 初赛] 独立

[THUPC 2021 初赛] 独立

Description

You are given an undirected graph with nn vertices and mm edges.

For a subset AA of {1,2,,n}\{1, 2, \ldots , n\}, the score of AA is defined as follows:

  1. The initial score is 00.
  2. For all iAi \in A, add aia_i to the score.
  3. For every edge (u,v,k)(u, v, k) (meaning an edge between uu and vv with value kk) such that uAu \in A and vAv \in A, subtract kk from the score.

Now, among all subsets AA, compute the maximum possible score.

Input Format

Let q=101q = 101, b=137b = 137, p=1,000,000,007p = 1, 000, 000, 007.

The first line contains six integers n,m,x0,y0,a0,z0n, m, x_0, y_0, a_0, z_0 (1n1000001 \le n \le 100000, 0mn20 \le m \le \frac n2, 0x0,y0,a0,z0<P0 \le x_0, y_0, a_0, z_0 < P).

For 1in1 \le i \le n, ai=(q×ai1+b)modpa_i = (q \times a_{i - 1} + b) \bmod p.

For 1im1 \le i \le m, xi=(q×xi1+b)modpx_i = (q \times x_{i − 1} + b) \bmod p, yi=(q×yi1+b)modpy_i = (q \times y_{i − 1} + b) \bmod p, zi=(q×zi1+b)modpz_i = (q \times z_{i − 1} + b) \bmod p. Each triple (xi,yi,zi)(x_i, y_i, z_i) describes an edge connecting (ximodn)+1(x_i \bmod n) + 1 and (yimodn)+1(y_i \bmod n) + 1 with value ziz_i. If xi=yix_i = y_i or an edge connecting xix_i and yiy_i has appeared before, ignore this edge (i.e., this edge does not exist).

Output Format

Output one line with one integer, the maximum score.

10 5 1 2 3 4

3909327860

Hint

[Source]

From the 2021 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2021) Preliminary Round.

Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2021-pre.

Translated by ChatGPT 5