1. Abridged Problem Statement  
A network of N computers forms a tree: the very first computer is node 1, and each new computer i (2≤i≤N) connects to exactly one earlier computer with a cable of given length. For each computer i, compute Si = the maximum total cable length on a path from i to any other computer in the network.

2. Detailed Editorial  
- We have a weighted tree of N nodes. For each node, we want its eccentricity: the greatest distance to any other node.  
- A well-known fact about trees is that the farthest pair of nodes (the diameter endpoints) can be found by two breadth-first or depth-first searches (BFS/DFS):  
  1. Start at an arbitrary node A, do a DFS to find the farthest node U from A.  
  2. From U, do another DFS to find the farthest node V; the path U–V is a diameter of the tree.  
- Let distU[i] be the distance from U to node i, and distV[i] the distance from V to node i. Then for any node i, the eccentricity Si = max(distU[i], distV[i]).  
- This works because every longest path from i to some other node must end at one of the diameter endpoints U or V.  
- Complexity: each DFS is O(N), so overall O(N). N≤10 000, total cable length ≤10^9, fits time/memory limits.

3. Provided C++ Solution with Detailed Comments  
#include <bits/stdc++.h>  
using namespace std;

// Read input size and build adjacency list
int n;  
vector<vector<pair<int,int>>> adj;  // adj[u] = list of (neighbor, weight)

// Read N and the N-1 connections
void read() {
    cin >> n;
    adj.assign(n, {});  
    // For i from 1 to n-1 (0-based), read its parent u and cable length w
    for(int i = 1; i < n; i++) {
        int u, w;
        cin >> u >> w;
        u--;  // convert to 0-based
        // add undirected edge between i and u
        adj[i].push_back({u, w});
        adj[u].push_back({i, w});
    }
}

// Return vector dist where dist[i] = distance from src to i
vector<int> get_distances(int src) {
    vector<int> dist(n, -1);
    // Recursive DFS: u=current, p=parent
    function<void(int,int)> dfs = [&](int u, int p) {
        for(auto &edge : adj[u]) {
            int v = edge.first;
            int w = edge.second;
            if(v == p) continue;           // skip parent
            dist[v] = dist[u] + w;         // accumulate distance
            dfs(v, u);                     // visit child
        }
    };
    dist[src] = 0;
    dfs(src, -1);
    return dist;
}

void solve() {
    // 1) DFS from node 0 to find one end of diameter
    vector<int> dist0 = get_distances(0);
    int diam_end_1 = max_element(dist0.begin(), dist0.end()) - dist0.begin();
    // 2) DFS from diam_end_1 to find the other end and record dist1[]
    vector<int> dist1 = get_distances(diam_end_1);
    int diam_end_2 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
    // 3) DFS from diam_end_2 to get dist2[]
    vector<int> dist2 = get_distances(diam_end_2);
    // 4) For every node i, answer = max(dist1[i], dist2[i])
    for(int i = 0; i < n; i++) {
        cout << max(dist1[i], dist2[i]) << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    read();      // read input
    solve();     // compute and output answers
    return 0;
}

4. Python Solution with Detailed Comments  
import sys  
sys.setrecursionlimit(20000)

def read_tree():
    input_data = sys.stdin.read().split()
    it = iter(input_data)
    n = int(next(it))
    adj = [[] for _ in range(n)]
    # Each of the next n-1 lines: parent u, weight w
    for i in range(1, n):
        u = int(next(it)) - 1
        w = int(next(it))
        adj[i].append((u, w))
        adj[u].append((i, w))
    return n, adj

def get_distances(n, adj, src):
    dist = [-1] * n
    dist[src] = 0
    # DFS to fill dist[]
    def dfs(u, parent):
        for v, w in adj[u]:
            if v == parent: continue
            dist[v] = dist[u] + w
            dfs(v, u)
    dfs(src, -1)
    return dist

def main():
    n, adj = read_tree()
    # 1) from arbitrary node 0
    dist0 = get_distances(n, adj, 0)
    # find farthest from 0
    u = max(range(n), key=lambda i: dist0[i])
    # 2) from u
    dist_u = get_distances(n, adj, u)
    # farthest from u
    v = max(range(n), key=lambda i: dist_u[i])
    # 3) from v
    dist_v = get_distances(n, adj, v)
    # 4) answer for i is max(dist_u[i], dist_v[i])
    out = "\n".join(str(max(dist_u[i], dist_v[i])) for i in range(n))
    print(out)

if __name__ == "__main__":
    main()

5. Compressed Editorial  
To compute every node’s eccentricity in a weighted tree, find two diameter endpoints U and V by running two DFS/BFS traversals: one from an arbitrary node to find U, then from U to find V. Record distances distU[] and distV[]. For each node i, its maximum distance to any other node is max(distU[i], distV[i]).