CF1633E.Spanning Tree Queries

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a connected weighted undirected graph, consisting of nn vertices and mm edges.

You are asked kk queries about it. Each query consists of a single integer xx. For each query, you select a spanning tree in the graph. Let the weights of its edges be w1,w2,…,wn−1w_1, w_2, \dots, w_{n-1}. The cost of a spanning tree is ∑i=1n−1∣wi−x∣\sum \limits_{i=1}^{n-1} |w_i - x| (the sum of absolute differences between the weights and xx). The answer to a query is the lowest cost of a spanning tree.

The queries are given in a compressed format. The first pp (1≤p≤k)(1 \le p \le k) queries q1,q2,…,qpq_1, q_2, \dots, q_p are provided explicitly. For queries from p+1p+1 to kk, qj=(qj−1⋅a+b)mod  cq_j = (q_{j-1} \cdot a + b) \mod c.

Print the xor of answers to all queries.

给你一个包含 nn 个顶点和 mm 条边的连通带权无向图。

你需要回答 kk 个查询。每个查询给出一个整数 xx。对于每个查询,你需要在图中选择一棵生成树。设该生成树各边的权重为 w1,w2,…,wn−1w_1, w_2, \dots, w_{n-1}。该生成树的代价定义为 ∑i=1n−1∣wi−x∣\sum \limits_{i=1}^{n-1} |w_i - x|(即所有边权与 xx 的绝对差之和)。查询的答案即为所有可能生成树中的最小代价。

这些查询以压缩形式给出:前 pp 个查询(1≤p≤k1 \le p \le k)q1,q2,…,qpq_1, q_2, \dots, q_p 被显式给出;而从第 p+1p+1 个到第 kk 个查询,按如下方式递推生成:qj=(qj−1⋅a+b)mod  cq_j = (q_{j-1} \cdot a + b) \mod c。

请输出所有查询答案的异或(xor)值。

输入格式

The first line contains two integers nn and mm (2≤n≤502 \le n \le 50; n−1≤m≤300n - 1 \le m \le 300) — the number of vertices and the number of edges in the graph.

Each of the next mm lines contains a description of an undirected edge: three integers vv, uu and ww (1≤v,u≤n1 \le v, u \le n; v≠uv \neq u; 0≤w≤1080 \le w \le 10^8) — the vertices the edge connects and its weight. Note that there might be multiple edges between a pair of vertices. The edges form a connected graph.

The next line contains five integers p,k,a,bp, k, a, b and cc (1≤p≤1051 \le p \le 10^5; p≤k≤107p \le k \le 10^7; 0≤a,b≤1080 \le a, b \le 10^8; 1≤c≤1081 \le c \le 10^8) — the number of queries provided explicitly, the total number of queries and parameters to generate the queries.

The next line contains pp integers q1,q2,…,qpq_1, q_2, \dots, q_p (0≤qj<c0 \le q_j \lt c) — the first pp queries.

第一行包含两个整数 nn 和 mm(2≤n≤502 \le n \le 50;n−1≤m≤300n - 1 \le m \le 300)—— 分别表示图中顶点的数量和边的数量。

接下来的 mm 行,每行描述一条无向边:三个整数 vv、uu 和 ww(1≤v,u≤n1 \le v, u \le n;v≠uv \neq u;0≤w≤1080 \le w \le 10^8)—— 表示该边所连接的两个顶点及其权重。注意:一对顶点之间可能存在多条边。所有边构成一个连通图。

接下来的一行包含五个整数 pp、kk、aa、bb 和 cc(1≤p≤1051 \le p \le 10^5;p≤k≤107p \le k \le 10^7;0≤a,b≤1080 \le a, b \le 10^8;1≤c≤1081 \le c \le 10^8)—— 分别表示显式给出的查询数量、查询总数以及用于生成查询的参数。

下一行包含 pp 个整数 q1,q2,…,qpq_1, q_2, \dots, q_p(0≤qj<c0 \le q_j \lt c)—— 表示前 pp 个查询。

输出格式

Print a single integer — the xor of answers to all queries.

输出一个整数——所有查询答案的异或值。

输入输出样例

  • 输入#1

    5 8
    4 1 4
    3 1 0
    3 5 3
    2 5 4
    3 4 8
    4 3 4
    4 2 8
    5 3 9
    3 11 1 1 10
    0 1 2

    输出#1

    4
  • 输入#2

    6 7
    2 4 0
    5 4 7
    2 4 0
    2 1 7
    2 6 1
    3 4 4
    1 4 8
    4 10 3 3 7
    3 0 2 1

    输出#2

    5
  • 输入#3

    3 3
    1 2 50
    2 3 100
    1 3 150
    1 10000000 0 0 100000000
    75

    输出#3

    164

说明/提示

The queries in the first example are 0,1,2,3,4,5,6,7,8,9,00, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0. The answers are 11,9,7,3,1,5,8,7,5,7,1111, 9, 7, 3, 1, 5, 8, 7, 5, 7, 11.

The queries in the second example are 3,0,2,1,6,0,3,5,4,13, 0, 2, 1, 6, 0, 3, 5, 4, 1. The answers are 14,19,15,16,11,19,14,12,13,1614, 19, 15, 16, 11, 19, 14, 12, 13, 16.

The queries in the third example are 75,0,0,…75, 0, 0, \dots. The answers are 50,150,150,…50, 150, 150, \dots.

第一个示例中的查询序列为 0,1,2,3,4,5,6,7,8,9,00, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,对应答案为 11,9,7,3,1,5,8,7,5,7,1111, 9, 7, 3, 1, 5, 8, 7, 5, 7, 11。

第二个示例中的查询序列为 3,0,2,1,6,0,3,5,4,13, 0, 2, 1, 6, 0, 3, 5, 4, 1,对应答案为 14,19,15,16,11,19,14,12,13,1614, 19, 15, 16, 11, 19, 14, 12, 13, 16。

第三个示例中的查询序列为 75,0,0,…75, 0, 0, \dots,对应答案为 50,150,150,…50, 150, 150, \dots。

输入解题思路,AI测评打分。不知道怎么写?

首页