-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathpart2.rs
34 lines (33 loc) · 904 Bytes
/
part2.rs
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
use std::collections::HashSet;
use std::io;
use std::io::prelude::*;
use std::vec::Vec;
fn main() {
let stdin = io::stdin();
let mut g: Vec<HashSet<_>> = vec![HashSet::new(); 26];
for line in stdin.lock().lines() {
let b = line.unwrap().into_bytes();
let u = (b[5] - 65) as usize;
let v = (b[36] - 65) as usize;
g[v].insert(u);
}
let mut s = HashSet::new();
let mut p = vec![];
for _ in 0..26 {
for i in 0..26 {
if s.contains(&i) {
continue;
}
if g[i].difference(&s).collect::<HashSet<_>>().is_empty() {
s.insert(i);
p.push(i);
break;
}
}
}
let mut t = vec![0; 26];
for i in p {
t[i] = g[i].iter().map(|&j| t[j]).max().unwrap_or(0) + 61 + i;
}
println!("{}", t.iter().max().unwrap());
}