-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path9.js
More file actions
40 lines (33 loc) · 867 Bytes
/
9.js
File metadata and controls
40 lines (33 loc) · 867 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
let getResult = (data) => {
let parse_ints = str => {
return str.split(' ').filter(val => val != '').map(val => parseInt(val.trim()));
}
let n = parseInt(data[0]);
let arr = [0, ...parse_ints(data[1])];
let max = 0;
let cur = 1;
for (let i = 1; i <= n; i++) {
if (i !== 0){
let next = arr[i];
let prev = i;
while (next !== i && next !== 0) {
prev = next;
next = arr[next];
arr[prev] = 0;
cur++;
}
arr[i] = 0;
}
max = Math.max(max, cur);
cur = 1;
}
return max;
}
const { count } = require('console');
//console.log('start: ' + Date.now());
const fs = require('fs');
let fileContent = fs.readFileSync("input.txt", "utf8");
const data = fileContent.toString().trim().split("\n");
const result = getResult(data);
fs.writeFileSync("output.txt", result.toString());
//console.log('end: ' + Date.now());