JavaScript的基础

f

寻找最富裕小家庭 前面几行应该都是套话

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);

// 这里头插一个0,是为了让wealth数组索引对应成员编号 1~N
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));
})();
/*
5
100 200 300 400 500
3 4
3 5
1 3
1 2
*/

JavaScript的基础
https://rain_dew.gitee.io/2024/04/16/其他/语言/JavaScript/
Author
Wang yulu
Posted on
April 16, 2024
Licensed under