QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#2893. Independent

统计

Given an undirected graph with $n$ vertices and $m$ edges. For a subset $A$ of $\{1, 2, \dots, n\}$, the score of $A$ is defined as: 1. The initial score is 0; 2. For all $i \in A$, add $a_i$ to the score; 3. For all edges $(u, v, k)$ (representing an edge between $u$ and $v$ with value $k$) such that $u \in A$ and $v \in A$, subtract $k$ from the score.

Please calculate the maximum possible score among all subsets $A$.

Input

Read data from standard input. Let $q = 101, b = 137, p = 1,000,000,007$. The first line contains six integers $n, m, x_0, y_0, a_0, z_0$ ($1 \le n \le 100000, 0 \le m \le \frac{n}{2}, 0 \le x_0, y_0, a_0, z_0 < p$).

For $1 \le i \le n$, $a_i = (q \times a_{i-1} + b) \pmod p$. For $1 \le i \le m$, $x_i = (q \times x_{i-1} + b) \pmod p$, $y_i = (q \times y_{i-1} + b) \pmod p$, $z_i = (q \times z_{i-1} + b) \pmod p$. Each triplet $(x_i, y_i, z_i)$ describes an edge connecting $(x_i \pmod n) + 1$ and $(y_i \pmod n) + 1$ with value $z_i$. If $x_i = y_i$ or an edge connecting $x_i$ and $y_i$ has appeared before, ignore this edge (i.e., the edge does not exist).

Output

Output to standard output. Output a single integer representing the maximum score.

Examples

Input 1

1 10 5 1 2 3 4

Output 1

3909327860

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.