编程介的小学生 2019-02-05 19:00 采纳率: 20.5%
浏览 346

二叉树的链表存储,线索二叉树的算法问题,怎么使用C语言实现节点遍历

Problem Description
Teacher Mai has m+1 trees, T0,T1,⋯,Tm. T0 consists one vertex numbered 0.

He generated the Ti in this way. Get a copy of Tai and Tbi. Add an edge with length li between vertex numbered ci in T′ai and di in T′bi. Relabel the vertices in the new tree. Let k be the number of vertices in T′ai. He keeps labels of vertices in T′ai the same, and adds k to labels of vertices in T′bi.

If there is a tree T with n vertices v0,v1,v2,⋯,vn−1, F(T)=∑n−1i=0∑n−1j=i+1d(vi,vj)(d(vi,vj) means the distance between the vi and vj).

For every i(1≤i≤m), he wants to know F(Ti).

Input
There are multiple test cases(about 100).

For each test case, the first line contains one number m(1≤m≤60), the following are m lines. The i-th lines contains five numbers ai,bi,ci,di,li(0≤ai,bi<i,0≤li≤109). It's guarenteed that there exists a vertex numbered ci in Tai and there exists a vertex numbered di in Tbi.

Output
For each test case, print F(Ti) modulo 109+7 in the i-th line.

Sample Input
3
0 0 0 0 2
1 1 0 0 4
2 2 1 0 3

Sample Output
2
28
216

  • 写回答

0条回答

    报告相同问题?

    问题事件

    • 请提交代码 11月3日

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘