Rikka with Minimum Spanning Trees徐州区域赛a题

这是一道关于最小生成树(MST)的题目,Rikka提供了通过随机数生成器构造的图。你需要计算所有MST的边权重之和的模(10^9 + 7),并利用Kirchhoff's矩阵树定理和Kruskal算法的性质来解决。输入包含多个测试用例,每个用例给出图的节点数、边数以及随机种子。
摘要由CSDN通过智能技术生成

Hello everyone! I am your old friend Rikka. Welcome to Xuzhou. This is the first problem, which is a problem about the minimum spanning tree (MST). I promise you all that this should be the \textbf{easiest problem}easiest problem for most people.

A minimum spanning tree, or minimum weight spanning tree, is a subset of edges from an edge-weighted undirected graph, which forms a tree with the minimum possible total edge weight that connects all the vertices together without any cycles.

In this problem, Rikka wants you to calculate the summation of total edge weights through all MSTs for a given graph, which obviously equals to the product of the total edge weight in an MST and the total number of different MSTs. Note that two spanning trees are different if the sets of their edges are different. In addition, a disconnected graph could have no MSTs, the number of whose different MSTs is zero.

To decrease the size of the input, Rikka provides an edge-weighted undirected graph via a random number generator with given random seeds, denoted by two integers k_1k
1

and k_2k
2

. Supposing the number of vertices and edges in the graph are nn and mm respectively, the following code in C++ tells you how to generate the graph and store the ii-th edge between the vertex u[i]u[i] and v[i]v[i] with weight w[i]w[i] in corresponding arrays. You can use the code directly in your submissions.

1
unsigned long long k1, k2;
2

3
unsigned long long xorShift128Plus() {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值