eolymp
bolt
Try our new interface for solving problems
Problems

Control chain

Control chain

Rybka decided to measure criticality of Watson’s control chain, which consists of N nodes, joined by conductors. Signal can be transmitted from any node to any other node trough the only possible path. When one of nodes comes under external action, it transmits signal to every other node. That is after external action the node creates \textbf{(N--1)} signals. \textbf{i}-node intensity (\textbf{iNode}) of conductor is defined as product of its length to the number of signals, that go through it after external action to the node \textbf{i}. The conductor is considered to be \textbf{i}-critical, if its \textbf{iNode} is maximal among all other conductors (with fixed \textbf{i}). If several equal \textbf{iNode} exist, several conductors are considered to be \textbf{i}-critical. Total criticality of the conductor is defined as count of its \textbf{i}-criticalities. Criticality of complete chain is defined as maximum of total criticalities of its conductors. \InputFile The first line contains one integer \textbf{N} -- number of nodes, following \textbf{(N-1)} lines describe conductors, each line contains \textbf{3} integers \textbf{i}, \textbf{j}, \textbf{A} -- describes a conductor that connects nodes \textbf{i} and \textbf{j} and has length \textbf{A}. \textbf{2} ≤ \textbf{N} ≤ \textbf{10^5}, (\textbf{1} ≤ \textbf{i}, \textbf{j} ≤ \textbf{N}, \textbf{1} ≤ \textbf{A} ≤ \textbf{10^5}). \OutputFile You need to print criticality of the chain. \textit{\textbf{Hint}}: In the chain: \textbf{1}-critical conductor \textbf{1}; \textbf{2}-critical: \textbf{1}, \textbf{2}; \textbf{3}-critical: \textbf{1}; \textbf{4}-critical: \textbf{3}; \textbf{5}-critical: \textbf{4}. Hence, the first conductor has \textbf{3} criticalities, so its total criticality is \textbf{3}, total criticality of other conductors is \textbf{1}, criticality of the chain equals to maximum of conductors’ criticalities, that is \textbf{3}.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
5
1 2 3
2 3 1
3 4 1
3 5 1
Output example #1
3