use std::iter;
fn main() {
let mut lines = std::io::stdin().lines();
let kn_1 = lines
.next()
.unwrap()
.unwrap()
.split_whitespace()
.map(|x| str::parse(x).unwrap())
.collect::<Vec<i32>>();
let descs = iter::once((0..kn_1[1]).map(|_| 0).collect())
.chain((2..=kn_1[0]).map(|_| {
lines
.next()
.unwrap()
.unwrap()
.split_whitespace()
.skip(1)
.map(|x| str::parse(x).unwrap())
.collect()
}))
.collect::<Vec<Vec<i32>>>();
let mut needs = descs
.iter()
.map(|x| x.iter().map(|_| 0).collect())
.collect::<Vec<Vec<i32>>>();
for f in needs[kn_1[0] as usize - 1].iter_mut() {
*f = 1;
}
// eprintln!("{:?} {:?}", descs, needs);
for i in (0..(kn_1[0] - 1)).rev() {
let (l, r) = needs.split_at_mut(i as usize + 1);
let this = l.last_mut().unwrap();
let next = r.first().unwrap();
// eprintln!("{:?} {:?}", this, next);
for (desc, need) in descs[i as usize + 1].iter().copied().zip(next.iter()) {
if desc > 0 {
this[desc as usize - 1] += need;
}
}
// eprintln!("{:?} {:?}", this, next);
for f in this.iter_mut() {
if *f == 0 {
*f = 1;
}
}
// eprintln!("{:?} {:?}", this, next);
}
println!(
"{}",
needs.iter().map(|x| x.iter().sum::<i32>()).max().unwrap()
);
}
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | use std::iter; fn main() { let mut lines = std::io::stdin().lines(); let kn_1 = lines .next() .unwrap() .unwrap() .split_whitespace() .map(|x| str::parse(x).unwrap()) .collect::<Vec<i32>>(); let descs = iter::once((0..kn_1[1]).map(|_| 0).collect()) .chain((2..=kn_1[0]).map(|_| { lines .next() .unwrap() .unwrap() .split_whitespace() .skip(1) .map(|x| str::parse(x).unwrap()) .collect() })) .collect::<Vec<Vec<i32>>>(); let mut needs = descs .iter() .map(|x| x.iter().map(|_| 0).collect()) .collect::<Vec<Vec<i32>>>(); for f in needs[kn_1[0] as usize - 1].iter_mut() { *f = 1; } // eprintln!("{:?} {:?}", descs, needs); for i in (0..(kn_1[0] - 1)).rev() { let (l, r) = needs.split_at_mut(i as usize + 1); let this = l.last_mut().unwrap(); let next = r.first().unwrap(); // eprintln!("{:?} {:?}", this, next); for (desc, need) in descs[i as usize + 1].iter().copied().zip(next.iter()) { if desc > 0 { this[desc as usize - 1] += need; } } // eprintln!("{:?} {:?}", this, next); for f in this.iter_mut() { if *f == 0 { *f = 1; } } // eprintln!("{:?} {:?}", this, next); } println!( "{}", needs.iter().map(|x| x.iter().sum::<i32>()).max().unwrap() ); } |
English