結果
問題 | No.806 木を道に |
ユーザー | kei |
提出日時 | 2019-08-28 21:20:58 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 4,938 bytes |
コンパイル時間 | 10,081 ms |
コンパイル使用メモリ | 405,212 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-11-17 16:37:05 |
合計ジャッジ時間 | 11,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 9 ms
5,248 KB |
testcase_11 | AC | 7 ms
5,248 KB |
testcase_12 | AC | 32 ms
14,592 KB |
testcase_13 | AC | 21 ms
11,136 KB |
testcase_14 | AC | 29 ms
14,080 KB |
testcase_15 | AC | 31 ms
14,848 KB |
testcase_16 | AC | 11 ms
6,528 KB |
testcase_17 | AC | 27 ms
13,056 KB |
testcase_18 | AC | 4 ms
5,248 KB |
testcase_19 | AC | 9 ms
5,504 KB |
testcase_20 | AC | 27 ms
13,056 KB |
testcase_21 | AC | 15 ms
8,192 KB |
testcase_22 | AC | 37 ms
17,024 KB |
testcase_23 | AC | 37 ms
16,896 KB |
testcase_24 | AC | 15 ms
9,856 KB |
testcase_25 | AC | 21 ms
13,696 KB |
testcase_26 | AC | 9 ms
7,040 KB |
testcase_27 | AC | 29 ms
18,688 KB |
testcase_28 | AC | 2 ms
5,248 KB |
ソースコード
#![allow(unused_mut, non_snake_case, unused_imports, dead_code,unused_macros)] use std::iter; use std::cmp::{max, min, Ordering}; use std::mem::swap; use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque}; use std::iter::FromIterator; // 高速 EOF要 //macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};} //macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};} //macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};} // 低速 EOF不要 macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};} macro_rules! mut_input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };mut_input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};mut_input_inner!{next, $($r)*}};} macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};} macro_rules! mut_input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let mut $var = read_value!($next, $t);mut_input_inner!{$next $($r)*}};} macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};} // 非常時 fn read_line() -> String { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } #[derive(Copy, Clone)] pub struct Edge{ from:usize, to:usize, cost:i64 } #[derive(Clone)] pub struct Graph{ N:usize, Edges:Vec<Vec<Edge>> } impl Graph{ pub fn new(n:usize) -> Graph{ Graph{N:n,Edges:vec![vec![];n]} } pub fn add_edge(&mut self,u:usize,v:usize,cost:i64,undirected:bool){ self.Edges[u].push(Edge{from:u,to:v,cost}); if undirected { self.Edges[v].push(Edge{from:v,to:u,cost}) } } pub fn Dijkstra(&self,root:usize) -> Vec<i64>{ let mut dist = vec![i64::max_value() as i64;self.N]; dist[root] = 0; let mut pq = BinaryHeap::new(); pq.push((0_i64,root)); while !pq.is_empty(){ let s = pq.pop().unwrap(); let (d,n) = (-s.0,s.1); if dist[n] < d { continue; } for e in &self.Edges[n]{ if dist[e.to] > dist[e.from] + e.cost{ dist[e.to] = dist[e.from] + e.cost; pq.push((-dist[e.to],e.to)); } } } return dist; } } fn solve(){ input!(N:usize,E:[(usize,usize);N-1]); let E:Vec<(usize,usize)> = E; let N:usize = N; let mut G = Graph::new(N); for e in E{ G.add_edge(e.0-1,e.1-1,1,true); } let mut ans = 0; for e in G.Edges{ if e.len() >= 3{ ans += e.len()-2; } } println!("{}",ans); } fn main() { let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }