結果

問題 No.1480 Many Complete Graphs
ユーザー akakimidoriakakimidori
提出日時 2021-04-16 21:05:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,556 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 155,392 KB
実行使用メモリ 20,460 KB
最終ジャッジ日時 2023-09-16 02:52:38
合計ジャッジ時間 5,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,500 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 17 ms
8,636 KB
testcase_14 AC 10 ms
6,484 KB
testcase_15 AC 26 ms
9,968 KB
testcase_16 AC 18 ms
7,776 KB
testcase_17 AC 15 ms
7,260 KB
testcase_18 AC 5 ms
4,832 KB
testcase_19 AC 17 ms
7,144 KB
testcase_20 AC 23 ms
8,236 KB
testcase_21 AC 15 ms
8,800 KB
testcase_22 AC 9 ms
5,500 KB
testcase_23 AC 32 ms
15,096 KB
testcase_24 AC 28 ms
10,712 KB
testcase_25 AC 53 ms
13,972 KB
testcase_26 AC 60 ms
15,320 KB
testcase_27 AC 30 ms
10,868 KB
testcase_28 AC 38 ms
17,968 KB
testcase_29 AC 39 ms
18,248 KB
testcase_30 AC 38 ms
17,724 KB
testcase_31 AC 37 ms
17,988 KB
testcase_32 AC 38 ms
18,272 KB
testcase_33 AC 38 ms
17,932 KB
testcase_34 AC 38 ms
18,264 KB
testcase_35 AC 37 ms
17,692 KB
testcase_36 AC 37 ms
17,688 KB
testcase_37 AC 37 ms
17,716 KB
testcase_38 AC 36 ms
17,716 KB
testcase_39 AC 36 ms
17,696 KB
testcase_40 AC 37 ms
17,704 KB
testcase_41 AC 37 ms
17,700 KB
testcase_42 AC 38 ms
18,280 KB
testcase_43 AC 37 ms
17,992 KB
testcase_44 AC 37 ms
17,968 KB
testcase_45 AC 39 ms
18,252 KB
testcase_46 AC 37 ms
17,984 KB
testcase_47 AC 87 ms
18,652 KB
testcase_48 AC 86 ms
18,656 KB
testcase_49 AC 88 ms
18,636 KB
testcase_50 AC 45 ms
18,344 KB
testcase_51 AC 89 ms
18,668 KB
testcase_52 AC 58 ms
18,008 KB
testcase_53 AC 57 ms
18,016 KB
testcase_54 AC 60 ms
18,004 KB
testcase_55 AC 60 ms
17,960 KB
testcase_56 AC 59 ms
17,964 KB
testcase_57 AC 35 ms
20,460 KB
testcase_58 AC 40 ms
16,500 KB
evil_aftercontest.txt AC 82 ms
30,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `out`
  --> Main.rs:42:45
   |
42 | fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
   |                                             ^^^ help: if this is intentional, prefix it with an underscore: `_out`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

// ---------- 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::io::Write;

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 n: usize = sc.next();
    let m: usize = sc.next();
    let mut g = vec![vec![]; n + 1];
    for _ in 0..m {
        let k: usize = sc.next();
        let c: u64 = sc.next();
        let s: Vec<usize> = sc.next_vec(k);
        let zero = g.len();
        g.push(vec![]);
        let one = g.len();
        g.push(vec![]);
        for &s in s.iter() {
            let d = (s / 2) as u64;
            if s & 1 == 0 {
                g[s].push((zero, c + d));
                g[zero].push((s, d));
                g[one].push((s, d));
            } else {
                g[s].push((one, c + d + 1));
                g[zero].push((s, d + 1));
                g[one].push((s, d));
            }
        }
    }
    use std::cmp::Reverse;
    let inf = std::u64::MAX;
    let mut dp = vec![inf; g.len()];
    dp[1] = 1;
    let mut h = std::collections::BinaryHeap::new();
    h.push(Reverse((0, 1)));
    while let Some(Reverse((d, v))) = h.pop() {
        if d > dp[v] {
            continue;
        }
        for &(u, w) in g[v].iter() {
            let d = d + w;
            if d < dp[u] {
                dp[u] = d;
                h.push(Reverse((d, u)));
            }
        }
    }
    if dp[n] != inf {
        println!("{}", dp[n]);
    } else {
        println!("-1");
    }
}
0