input: from typing import List, Tuple
  
  def count_pairs_of_connectable_servers(edges: List[Tuple[int, int, int]], signalSpeed: int) -> List[int]:
      """
      You are given an unrooted weighted tree with n vertices representing servers numbered from 0 to n - 1, an array edges where edges[i] = [a_i, b_i, weighti] represents a bidirectional edge between vertices a_i and b_i of weight weight_i. You are also given an integer signalSpeed.
  
      Two servers a and b are connectable through a server c if:
  
      a < b, a != c and b != c.
      The distance from c to a is divisible by signalSpeed.
      The distance from c to b is divisible by signalSpeed.
      The path from c to b and the path from c to a do not share any edges.
      Return an integer array count of length n where count[i] is the number of server pairs that are connectable through the server i.
  
      Examples:
      >>> edges = [[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]], signalSpeed = 1
      [0,4,6,6,4,0]
      >>> edges = [[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]], signalSpeed = 3
      [2,0,0,0,0,0,2]
  
      Constraints:
      2 <= n <= 1000
      edges.length == n - 1
      edges[i].length == 3
      0 <= a_i, b_i < n
      edges[i] = [a_i, b_i, weight_i]
      1 <= weight_i <= 10^6
      1 <= signalSpeed <= 10^6
      The input is generated such that edges represents a valid tree.
      """
  
output: 
      from collections import defaultdict
  
      n = len(edges) + 1
      graph = defaultdict(list)
      for a, b, weight in edges:
          graph[a].append((b, weight))
          graph[b].append((a, weight))
  
      def dfs(node, parent):
          distances = [0] * n
          stack = [(node, parent, 0)]
          while stack:
              current, par, dist = stack.pop()
              distances[current] = dist
              for neighbor, weight in graph[current]:
                  if neighbor != par:
                      stack.append((neighbor, current, dist + weight))
          return distances
  
      counts = [0] * n
      for i in range(n):
          distances_from_i = dfs(i, -1)
          for j in range(n):
              if i != j and distances_from_i[j] % signalSpeed == 0:
                  for k in range(j + 1, n):
                      if i != k and distances_from_i[k] % signalSpeed == 0:
                          if all(distances_from_i[x] % signalSpeed != 0 for x in range(j + 1, k)):
                              counts[i] += 1
  
      return counts
  