結果
問題 | No.2987 Colorful University of Tree |
ユーザー | akakimidori |
提出日時 | 2024-12-12 18:38:23 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,631 bytes |
コンパイル時間 | 16,286 ms |
コンパイル使用メモリ | 378,844 KB |
実行使用メモリ | 44,480 KB |
最終ジャッジ日時 | 2024-12-12 18:38:54 |
合計ジャッジ時間 | 29,765 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
99_evil_hack_000.txt | WA | - |
コンパイルメッセージ
warning: type alias `Map` is never used --> src/main.rs:56:6 | 56 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:57:6 | 57 | type Set<T> = BTreeSet<T>; | ^^^ warning: type alias `Deque` is never used --> src/main.rs:58:6 | 58 | type Deque<T> = VecDeque<T>; | ^^^^^
ソースコード
mod util { pub trait Join { fn join(self, sep: &str) -> String; } impl<T, I> Join for I where I: Iterator<Item = T>, T: std::fmt::Display, { fn join(self, sep: &str) -> String { let mut s = String::new(); use std::fmt::*; for (i, v) in self.enumerate() { if i > 0 { write!(&mut s, "{}", sep).ok(); } write!(&mut s, "{}", v).ok(); } s } } } // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { self.it.next().unwrap().parse::<T>().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::collections::*; use std::io::Write; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { let t: u32 = sc.next(); for _ in 0..t { let n: usize = sc.next(); let mut e = vec![vec![]; n]; for e in e.iter_mut() { let m = sc.next::<usize>(); e.resize(m, 0usize); for e in e.iter_mut() { *e = sc.next::<usize>() - 1; } } let (q, ans) = solve(e); writeln!(out, "{}", q).ok(); for (f, a) in ans { use util::*; writeln!(out, "{} {}", f + 1, a.iter().map(|a| *a + 1).join(" ")).ok(); } } } fn solve(e: Vec<Vec<usize>>) -> (usize, Vec<(usize, Vec<usize>)>) { let n = e.len(); let mut list = vec![vec![]; n - 1]; for (i, e) in e.iter().enumerate() { for e in e.iter() { list[*e].push(i); } } let deg = e.iter().map(|e| e.len()).collect::<Vec<_>>(); let mut q = (1..).find(|&p| p * p >= 2 * (n - 1)).unwrap().max(*deg.iter().max().unwrap()); if greedy(°, q).is_none() { q += 1; } assert!(greedy(°, q).is_some()); (0, vec![]) } fn greedy(a: &[usize], q: usize) -> Option<Vec<usize>> { let n = a.len(); assert!(a.iter().sum::<usize>() == 2 * (n - 1)); let mut rem = vec![q; q]; let mut h = std::collections::BinaryHeap::new(); for i in 0..q { h.push((q, i)); } let mut ans = vec![0; n]; let mut ord = (0..n).collect::<Vec<_>>(); ord.sort_by_key(|v| a[*v]); for x in ord.into_iter().rev() { let a = a[x]; let ans = &mut ans[x]; let (_, k) = h.pop().unwrap(); if rem[k] < a { return None; } *ans = k; rem[k] -= a; h.push((rem[k], k)); } Some(ans) }