Queries on tree 3 - MarisaOJ: Marisa Online Judge

Queries on tree 3

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree with n nodes, each node has a value of 1 or −1. For q queries (u,v), count the number of nodes t on the simple path from u to v such that the sum of node values on the simple path from u to t is positive. ### Input - The first line contains two integers n and q. - The second line contains n integers representing the values of the nodes from 1 to n. - The next n−1 lines each contain two integers u,v representing an edge of the tree. - The next q lines each contain two integers u,v representing a query. ### Output - For each query, print a single integer as the answer. ### Constraints - 1≤n,q≤105. - 1≤u,v≤n. ### Example Input: 85-1111-111-1155636454748123822172764 Output: 51022