COT - Count on a tree
You are given a tree with N nodes. The tree nodes are numbered from 1 to N. Each node has an integer weight.
We will ask you to perform the following operation:
- u v k : ask for the kth minimum weight on the path from node u to node v
In the first line there are two integers N and M. (N, M <= 100000)
In the second line there are N integers. The ith integer denotes the weight of the ith node.
In the next N-1 lines, each line contains two integers u v, which describes an edge (u, v).
In the next M lines, each line contains three integers u v k, which means an operation asking for the kth minimum weight on the path from node u to node v.
For each operation, print its result.
Input: 8 5 105 2 9 3 8 5 7 7 1 2 1 3 1 4 3 5 3 6 3 7 4 8
2 5 1
2 5 2
2 5 3
2 5 4
7 8 2
wtf n is not <= 1e5, wasted too much time, take limit of n 111111 to be on safe side..
the weights can be negative or bigger then 10^5 and that is why most people get WA on this problem
I found this Tc as the trickest one.
If we list the elements in the path from node 7 to node 8 in the given example, we'll get [7, 9, 105, 3, 7] . The 3rd minimum number in the list is 7 or 9?
Last edit: 2017-06-03 13:42:35
I am getting WA. Is there any tricky test case? I used persistent segment tree, and even used long long.Last edit: 2017-05-23 15:27:13
Last edit: 2017-02-16 09:49:50
n & m are greater than 10^5. cost me few wa :(
Very strict time limit. Had to use fast input output and then compress code :| :| due to source limit exceeding with fast input output -_-
getting seg fault in c++ 5.1 but got ac in c++ 4.3.2.Why??
|Cluster:||Cube (Intel G860)|
|Languages:||All except: ASM32-GCC ASM64 MAWK BC C-CLANG CPP14-CLANG CPP14 COBOL COFFEE D-DMD D-CLANG DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET|
|Resource:||Just for fun...|