Company: GoComet_11march
Difficulty: medium
You are given a network of radio devices represented as a tree structure. Each device transmits at an integer frequency of 1, 2, or 3 units. Two devices can communicate directly if the absolute difference between their frequencies is at most 1. The network consists of network_nodes devices and network_nodes - 1 edges. The edges are defined by two arrays: network_from and network_to , where an undirected edge connects network_from[i] to network_to[i] for 1 ≤ i < network_nodes. Additionally, an array called frequency provides the transmission frequency of each device. The distance between two devices is defined as the number of edges in a simple path connecting them. A simple path is a sequence in which each consecutive device is connected by an edge, and no device appears more than once. Your task is to determine the longest distance between any two devices that can transmit messages to each other. A device can transmit a message to another device if there exists a simple path bet