def METHOD_NAME(self, weights):
    from collections import defaultdict
    singles = defaultdict(set)
    for (s, d, _) in weights:
        singles[s].add(d)
        singles[d].add(s)
    return singles