hdu2586(How far away ?)
来源:互联网 发布:javascript实现选项卡 编辑:程序博客网 时间:2024/05/01 23:33
How far away ?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2561 Accepted Submission(s): 946
Problem Description
There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to go from house A to house B"? Usually it hard to answer. But luckily int this village the answer is always unique, since the roads are built in the way that there is a unique simple path("simple" means you can't visit a place twice) between every two houses. Yout task is to answer all these curious people.
Input
First line is a single integer T(T<=10), indicating the number of test cases.
For each test case,in the first line there are two numbers n(2<=n<=40000) and m (1<=m<=200),the number of houses and the number of queries. The following n-1 lines each consisting three numbers i,j,k, separated bu a single space, meaning that there is a road connecting house i and house j,with length k(0<k<=40000).The houses are labeled from 1 to n.
Next m lines each has distinct integers i and j, you areato answer the distance between house i and house j.
For each test case,in the first line there are two numbers n(2<=n<=40000) and m (1<=m<=200),the number of houses and the number of queries. The following n-1 lines each consisting three numbers i,j,k, separated bu a single space, meaning that there is a road connecting house i and house j,with length k(0<k<=40000).The houses are labeled from 1 to n.
Next m lines each has distinct integers i and j, you areato answer the distance between house i and house j.
Output
For each test case,output m lines. Each line represents the answer of the query. Output a bland line after each test case.
Sample Input
23 21 2 103 1 151 22 32 21 2 1001 22 1
Sample Output
1025100100
- hdu2586(How far away ?)
- hdu2586(How far away ?)
- HDU2586 How far away ?
- HDU2586 How far away ?
- hdu2586【How far away ?】
- HDU2586 How far away ?
- hdu2586 How far away
- hdu2586 How far away ?(LCA->RMQ)
- HDU2586 How far away?(树链剖分求LCA)
- hdu2586 How far away? LCA
- HDU2586 How far away ?(LCA离线算法)
- HDU2586 How far away ?(LCA在线RMQ-ST)
- hdu2586-LCA(tarjan法)-How far away ?
- HDU2586 How far away ?(LCA,Tarjan算法)
- hdu2586 how far away?(lca求距离)
- hdu2586 step5.3.4.cpp How far away ?
- [LCA Problem] hdu2586 How far away ?
- HDU2586 How far away ?(LCA模板题)
- request获得URL图解
- 结构型模式之组合模式(Composite)
- 【Android您问我讲】带左右滑动的选项卡
- 【昊昊带你学】DIY之SSD
- HTML表格细线设置
- hdu2586(How far away ?)
- Google Maps Android API V2的使用及问题解决
- 【昊昊带你学】神秘现象(提问帖)
- C++ 类型转换(Casting Operators)
- C++中引用(&)的用法和应用实例
- Makefiles in Linux: An Overview
- 【昊昊带你学】android-解决/data/dalvik-cache占用内存的问题
- 将来的手机,我心中的手机 【十年前的一篇随笔】
- 【昊昊带你学】VMWare+Mountain Lion