結果
問題 | No.2325 Skill Tree |
ユーザー | naut3 |
提出日時 | 2023-09-30 14:06:06 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 152 ms / 3,000 ms |
コード長 | 2,969 bytes |
コンパイル時間 | 18,095 ms |
コンパイル使用メモリ | 384,380 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-07-23 08:09:47 |
合計ジャッジ時間 | 25,246 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 22 ms
5,376 KB |
testcase_08 | AC | 33 ms
7,936 KB |
testcase_09 | AC | 32 ms
6,144 KB |
testcase_10 | AC | 54 ms
12,032 KB |
testcase_11 | AC | 43 ms
9,016 KB |
testcase_12 | AC | 98 ms
16,512 KB |
testcase_13 | AC | 103 ms
16,388 KB |
testcase_14 | AC | 100 ms
16,556 KB |
testcase_15 | AC | 102 ms
17,280 KB |
testcase_16 | AC | 99 ms
16,448 KB |
testcase_17 | AC | 97 ms
16,468 KB |
testcase_18 | AC | 96 ms
16,512 KB |
testcase_19 | AC | 95 ms
16,512 KB |
testcase_20 | AC | 98 ms
16,640 KB |
testcase_21 | AC | 96 ms
16,424 KB |
testcase_22 | AC | 104 ms
16,560 KB |
testcase_23 | AC | 105 ms
16,512 KB |
testcase_24 | AC | 101 ms
16,440 KB |
testcase_25 | AC | 104 ms
16,424 KB |
testcase_26 | AC | 112 ms
16,472 KB |
testcase_27 | AC | 152 ms
18,856 KB |
testcase_28 | AC | 147 ms
19,072 KB |
testcase_29 | AC | 143 ms
18,908 KB |
testcase_30 | AC | 146 ms
19,072 KB |
testcase_31 | AC | 148 ms
18,936 KB |
testcase_32 | AC | 136 ms
18,960 KB |
testcase_33 | AC | 139 ms
18,976 KB |
testcase_34 | AC | 140 ms
18,888 KB |
testcase_35 | AC | 144 ms
18,760 KB |
testcase_36 | AC | 144 ms
19,000 KB |
testcase_37 | AC | 151 ms
18,944 KB |
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let N = input!(usize); let mut graph = vec![vec![]; N]; for i in 1..N { let l = input!(usize); let a = input!(usize) - 1; graph[a].push((i, l)); } let mut lower = vec![0; N]; let mut seen = vec![false; N]; let mut q = std::collections::VecDeque::new(); q.push_front(0); seen[0] = true; while let Some(now) = q.pop_front() { for &(nxt, l) in graph[now].iter() { lower[nxt] = std::cmp::max(lower[nxt], std::cmp::max(l, lower[now])); q.push_back(nxt); seen[nxt] = true; } } // eprintln!( // "{}", // lower // .iter() // .map(|x| x.to_string()) // .collect::<Vec<_>>() // .join(" ") // ); let lower_sorted = { let mut L = vec![]; for i in 0..N { if seen[i] { L.push(lower[i]); } } L.sort(); L }; let Q = input!(usize); for _ in 0..Q { let t = input!(usize); let x = input!(usize); if t == 1 { let mut ok = 0; let mut ng = lower_sorted.len(); while ng - ok > 1 { let m = (ok + ng) / 2; if lower_sorted[m] <= x { ok = m; } else { ng = m; } } writeln!(out, "{}", ok + 1); } else { if !seen[x - 1] { writeln!(out, "-1"); } else { writeln!(out, "{}", lower[x - 1]); } } } } struct Scanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitWhitespace<'static>, } impl<R: BufRead> Scanner<R> { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }