编程介的小学生 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 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题