An integer N (1 ≤ N ≤ 100,000), representing some quantity or size.

A list of integers G of size N, where each integer is between 1 and 10,000.

A list of tuples of size N-1, where each tuple contains two integers A and B (1 ≤ A, B ≤ N, A ≠ B) and an integer D (1 ≤ D ≤ 10,000).

### Example Input:

```
5
5 8 1 3 5
1 2 4
2 3 3
2 4 3
1 5 7
```

### Function Signature:
Write a function f(N, G, roads) that takes in the input.
def f(N: int, G: List[int], roads: List[Tuple[int, int, int]]):
    '''
    N: an integer
    G: a list of integers
    roads: a list of tuples, where each tuple contains three integers
    '''
