結果

問題 No.1147 土偶Ⅱ
ユーザー phsplsphspls
提出日時 2020-08-05 23:14:14
言語 Rust
(1.72.1)
結果
AC  
実行時間 5 ms / 500 ms
コード長 1,439 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 159,168 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 18:57:59
合計ジャッジ時間 2,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused borrow that must be used
  --> Main.rs:24:9
   |
24 | /         &relations[i].iter().for_each(|&f| {
25 | |             if f == i { return; }
26 | |             (&relations[f]).iter().for_each(|&k| {
27 | |                 if !(&relations[k]).contains(&i) {
...  |
30 | |             });
31 | |         });
   | |__________^ the borrow produces a value
   |
   = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
   |
24 |         let _ = &relations[i].iter().for_each(|&f| {
   |         +++++++

warning: 1 warning emitted

ソースコード

diff #

use std::collections::HashSet;

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); 
    let n = nm[0];
    let m = nm[1];
    let mut relations: Vec<HashSet<usize>> = vec![HashSet::new(); n];
    for i in 0..n {
        relations[i].insert(i);
    }
    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] - 1;
        let b = ab[1] - 1;
        relations[a].insert(b);
        relations[b].insert(a);
    }
    let mut ffriends: Vec<HashSet<usize>> = vec![HashSet::new(); n];
    for i in 0..n {
        &relations[i].iter().for_each(|&f| {
            if f == i { return; }
            (&relations[f]).iter().for_each(|&k| {
                if !(&relations[k]).contains(&i) {
                    ffriends[i].insert(k);
                }
            });
        });
    }
    let mut result: usize = 0;
    for i in 0..n {
        for j in i+1..n {
            if ffriends[i].contains(&j) { continue; }
            for k in j+1..n {
                if ffriends[i].contains(&k) { continue; }
                if ffriends[j].contains(&k) { continue; }
                result += 1;
            }
        }
    }
    println!("{}", result);
}
0