编程介的小学生 2017-09-28 03:33 采纳率: 20.5%
浏览 715
已采纳

Maximum Spanning Forest

Problem Description
In graph theory, a maximum spanning tree is a subgraph that is a tree and connects all the vertices with maximum weight sum. And a maximum spanning forest is the union of maximum spanning trees of each connected component in the graph.

A big undirected graph G=(V,E) is given, which V={(x,y):1≤x,y≤2,000,000,000; x,y∈Z} and E={} initially. You're task is to write a program that support operation x1,y1,x2,y2,c:

First, add some edges in G. You should add an edge between (a1,b1) and (a2,b2) with weight c if x1≤a1,a2≤x2, y1≤b1,b2≤y2 and |a1−a2|+|b1−b2|=1.

Second, calculate the maximum spanning forest of G after edges added.

Input
The first line of input contains an integer T indicating the total number of test cases.

The first line of each test case has an integers n, indicating the number of operations. The n lines that follow describe the operations. Each of these lines has 5 integers x1,y1,x2,y2,c, separated by a single space.

Limitations:

1≤T≤500
1≤n≤100
1≤x1≤x2≤2,000,000,000
1≤y1≤y2≤2,000,000,000
1≤c≤1,000,000,000
There are at most 20 testcases with n>50.

Output
For each operation, output a number in a line that indicates the weight of maximum spanning forest mod 109+7.

Sample Input
2
3
2 2 3 3 1
1 2 2 3 2
1 1 1 3 5
1
1 1 2000000000 2000000000 1000000000

Sample Output
3
8
16
999998642

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-16 02:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?