結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | hatoo |
提出日時 | 2018-10-20 11:50:43 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 4,383 bytes |
コンパイル時間 | 13,361 ms |
コンパイル使用メモリ | 386,712 KB |
実行使用メモリ | 7,092 KB |
最終ジャッジ日時 | 2024-11-19 02:19:25 |
合計ジャッジ時間 | 13,757 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 5 ms
6,820 KB |
testcase_14 | AC | 9 ms
6,816 KB |
testcase_15 | AC | 7 ms
6,816 KB |
testcase_16 | AC | 17 ms
6,820 KB |
testcase_17 | AC | 38 ms
6,816 KB |
testcase_18 | AC | 42 ms
6,816 KB |
testcase_19 | AC | 46 ms
6,936 KB |
testcase_20 | AC | 42 ms
6,820 KB |
testcase_21 | AC | 42 ms
6,816 KB |
testcase_22 | AC | 1 ms
6,816 KB |
testcase_23 | AC | 1 ms
6,816 KB |
testcase_24 | AC | 1 ms
6,816 KB |
testcase_25 | AC | 36 ms
6,820 KB |
testcase_26 | AC | 41 ms
7,092 KB |
testcase_27 | AC | 43 ms
6,820 KB |
testcase_28 | AC | 29 ms
6,820 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::fmt::Debug; use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn chars() -> Vec<char> { line().chars().collect() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } #[allow(dead_code)] pub struct UFT { pub par: Vec<usize>, pub rank: Vec<usize>, } impl UFT { #[allow(dead_code)] pub fn new(n: usize) -> Self { UFT { par: (0..n).collect(), rank: vec![0; n], } } #[allow(dead_code)] pub fn root(&mut self, x: usize) -> usize { if self.par[x] == x { x } else { let p = self.par[x]; let pp = self.root(p); self.par[x] = pp; pp } } #[allow(dead_code)] pub fn merge(&mut self, x: usize, y: usize) { let x = self.root(x); let y = self.root(y); if x == y { return; } if self.rank[x] < self.rank[y] { self.par[x] = y; } else { self.par[y] = x; if self.rank[x] == self.rank[y] { self.rank[x] += 1; } } } } fn solve() { let (n, m, k) = get!(usize, usize, usize); let abc = get!(usize, usize, u64; m); let es = get!(usize; k); let mut ban = vec![false; m]; let mut uft = UFT::new(n); for e in es { ban[e - 1] = true; let (a, b, _) = abc[e - 1]; uft.merge(a - 1, b - 1); } let mut es: Vec<usize> = (0..m).collect(); es.sort_by_key(|&i| abc[i].2); let mut ans = 0; for e in es { if ban[e] { continue; } let (a, b, c) = abc[e]; if uft.root(a - 1) == uft.root(b - 1) { ans += c; } uft.merge(a - 1, b - 1); } println!("{}", ans); }