結果

問題 No.1340 おーじ君をさがせ
ユーザー phsplsphspls
提出日時 2022-11-19 22:28:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,125 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 190,784 KB
実行使用メモリ 9,360 KB
最終ジャッジ日時 2023-10-21 02:33:38
合計ジャッジ時間 15,226 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 16 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 219 ms
6,164 KB
testcase_22 AC 578 ms
7,844 KB
testcase_23 AC 210 ms
6,092 KB
testcase_24 AC 1,106 ms
9,276 KB
testcase_25 AC 19 ms
4,348 KB
testcase_26 AC 13 ms
4,348 KB
testcase_27 AC 9 ms
4,348 KB
testcase_28 AC 35 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 243 ms
6,320 KB
testcase_31 AC 1,125 ms
9,360 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 122 ms
4,348 KB
testcase_35 AC 124 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 845 ms
7,980 KB
testcase_40 AC 812 ms
7,868 KB
testcase_41 AC 813 ms
7,868 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 491 ms
7,272 KB
testcase_47 AC 493 ms
7,276 KB
testcase_48 AC 493 ms
7,276 KB
testcase_49 AC 875 ms
8,032 KB
testcase_50 AC 875 ms
8,032 KB
testcase_51 AC 876 ms
8,032 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 185 ms
5,828 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 1 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;


fn main() {
    let mut nmt = String::new();
    std::io::stdin().read_line(&mut nmt).ok();
    let nmt: Vec<usize> = nmt.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nmt[0];
    let m = nmt[1];
    let t = nmt[2];
    let mut paths = vec![vec![false; n]; n];
    for _ in 0..m {
        let mut ab = String::new();
        std::io::stdin().read_line(&mut ab).ok();
        let ab: Vec<usize> = ab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = ab[0];
        let b = ab[1];
        paths[a][b] = true;
    }

    let mut dp = vec![vec![HashSet::new(); n]];
    for i in 0..n {
        for j in 0..n {
            if paths[i][j] {
                dp[0][i].insert(j);
            }
        }
    }
    for i in 0..60 {
        let mut nexts = vec![HashSet::new(); n];
        for j in 0..n {
            for &u in dp[i][j].iter() {
                for &v in dp[i][u].iter() {
                    nexts[j].insert(v);
                }
            }
        }
        dp.push(nexts);
    }
    let mut result = HashSet::new();
    result.insert(0);
    for i in (0..60).rev() {
        if ((t >> i) & 1) == 0 { continue; }
        let mut nexts = HashSet::new();
        for &u in result.iter() {
            for &v in dp[i][u].iter() {
                nexts.insert(v);
            }
        }
        result = nexts;
    }
    println!("{}", result.len());
}
0