Special nodes path

Company: Trs_5aug

Difficulty: medium

Problem Statement

Special nodes path Problem Description You are given a tree with N nodes, numbered from 1 to N . Every edge of the tree has length 1 , and the distance between two nodes is the number of edges on the shortest path between them. K of the nodes are special . You must perform the following operation exactly once : Choose two different special nodes u and v and add a new edge of length 1 between them. After the operation the graph is no longer a tree, so there may be a new, shorter route between nodes. Find the minimum possible distance between node 1 and node N after performing the operation, choosing u and v as well as possible. Each input contains several independent test cases. Function Description Complete the function solve . It receives one test case and returns a single integer, the minimum distance between node 1 and node N after the operation. N : the number of nodes in the tree. K : the number of special nodes. special_nodes : an array of K integers, the special nodes. node_from