编程介的小学生 2019-01-08 00:20 采纳率: 20.5%
浏览 624
已采纳

一个有关多叉树的问题的采用了C语言的方式怎么实现多叉树

Problem Description
A graph G with n×m nodes forms a n×m grid with n×m vertices.
(n−1)×m weighted edges connect the vertices of adjacent rows, and n×(m−1) weighted edges connect the vertices of adjacent columns.

A spanning tree of graph G is a subgraph that is a tree and connects all the vertices together.
A minimum spanning tree (MST) or minimum weight spanning tree is then a spanning tree with weight less than or equal to the weight of every other spanning tree.
Graph G has many different minimum spanning trees.
For each MST T, the LRdeg(u) of node u is defined as the number of nodes, in the previous column or the previous row connecting with u, plus one.
And we define τ(T)=∏uLRdeg(u) as the product of LRdeg(u) for all nodes.

Your mission is to find the weight of the minimum spanning tree of graph G, and count τ(T) of all minimum spanning trees. Two MST(s) are considered different if they contain different subsets of edges.

Input
The input contains several test cases. The first line of the input is a single integer t (1≤t≤32) which is the number of test cases. Then t test cases follow.

For each test case, the first line contains the two integers n (1≤n≤800) and m (1≤m≤7).
Each line of the next n lines contains m−1 integers, which describe the weights of edges connecting the vertices of adjacent columns.
And each line of the next n−1 lines contains m integers, which describe the weights of edges connecting the vertices of adjacent rows. The weights of edges are no more than 10.

Output
For each test case, you should output two integers in one line. The first one is the weight of the minimum spanning tree.
The second one is the sum of τ(T) for all different minimum spanning trees, modulo 109+7.

Sample Input
2

2 5
9 8 5 6
4 6 2 3
1 7 8 3 8

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

Sample Output
Case #1: 37 288
Case #2: 96 4478976

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-12-29 00:32
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)