#P7146. [THUPC 2021 初赛] 独立

[THUPC 2021 初赛] 独立

Background

feecle6418 note: You may assume the testdata of this problem is generated randomly.

Problem 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 i∈Ai \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 u∈Au \in A and v∈Av \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 (1≤n≤1000001 \le n \le 100000, 0≤m≤n20 \le m \le \frac n2, 0≤x0,y0,a0,z0<P0 \le x_0, y_0, a_0, z_0 < P).

For 1≤i≤n1 \le i \le n, ai=(q×ai−1+b) mod pa_i = (q \times a_{i - 1} + b) \bmod p.

For 1≤i≤m1 \le i \le m, xi=(q×xi−1+b) mod px_i = (q \times x_{i − 1} + b) \bmod p, yi=(q×yi−1+b) mod py_i = (q \times y_{i − 1} + b) \bmod p, zi=(q×zi−1+b) mod pz_i = (q \times z_{i − 1} + b) \bmod p. Each triple (xi,yi,zi)(x_i, y_i, z_i) describes an edge connecting (xi mod n)+1(x_i \bmod n) + 1 and (yi mod n)+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