Maximum Node Sequence Score

A content delivery network has n service nodes labeled 0 to n - 1. Each node carries a reliability scores[i]. A service route jumps from one node to the next, but a route may only follow links that are physically provisioned, given as edges[i] = [ui, vi], meaning node ui shares a direct fiber link with node vi.

A route is called a relay chain when it visits exactly four distinct nodes, one after another, where every consecutive pair shares a direct link. The chain's worth is the sum of the reliability scores of the four visited nodes.

Find the worth of the most valuable relay chain. If no chain of four distinct linked nodes exists, return -1.

Examples
Input: [[5,2,9,8,4],[[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]]
Output: 24
Hints

Maximum Node Sequence Score

A content delivery network has `n` service nodes labeled `0` to `n - 1`. Each node carries a reliability `scores[i]`. A service route jumps from one node to the next, but a route may only follow links that are physically provisioned, given as `edges[i] = [ui, vi]`, meaning node `ui` shares a direct fiber link with node `vi`.