Company: Somehting
Difficulty: medium
Pythagorean Triples Problem Description There is a tree with tree_nodes nodes numbered 0 through tree_nodes - 1 . The distance between two nodes is the number of edges on the unique path between them. Three distinct target nodes x , y and z are given. A node u is special when its three distances dist(u, x) , dist(u, y) and dist(u, z) , sorted into a <= b <= c , satisfy a * a + b * b == c * c Return the number of special nodes. Input Format The first line contains tree_nodes . The second line contains tree_edges , which always equals tree_nodes - 1 . Each of the next tree_edges lines contains two integers u and v , an edge between u and v . The last line contains three integers x , y and z . Output Format Print a single integer: the number of special nodes. Constraints 3 <= tree_nodes <= 2500 tree_edges = tree_nodes - 1 , and the edges form a tree (connected, no cycle) 0 <= u, v < tree_nodes 0 <= x, y, z < tree_nodes , and x , y , z are distinct Examples Example