1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { const n = parseInt(await readline()); const wealth = (await readline()).split(" ").map(Number); wealth.unshift(0); const family = [...wealth]; for (let i = 0; i < n - 1; i++) { const [fa, ch] = (await readline()).split(" ").map(Number); family[fa] += wealth[ch]; } console.log(Math.max(...family)); })();
|