結果

問題 No.2319 Friends+
ユーザー so-heyso-hey
提出日時 2023-05-26 22:39:45
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,322 bytes
コンパイル時間 17,161 ms
コンパイル使用メモリ 377,124 KB
実行使用メモリ 397,056 KB
最終ジャッジ日時 2024-06-07 08:02:34
合計ジャッジ時間 48,758 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 701 ms
394,880 KB
testcase_08 AC 761 ms
394,880 KB
testcase_09 AC 776 ms
394,880 KB
testcase_10 AC 687 ms
394,752 KB
testcase_11 AC 723 ms
394,880 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2,486 ms
394,240 KB
testcase_19 AC 671 ms
395,008 KB
testcase_20 AC 782 ms
396,928 KB
testcase_21 AC 805 ms
396,928 KB
testcase_22 AC 685 ms
396,928 KB
testcase_23 AC 632 ms
396,032 KB
testcase_24 AC 641 ms
396,544 KB
testcase_25 AC 650 ms
396,800 KB
testcase_26 AC 644 ms
396,928 KB
testcase_27 AC 647 ms
397,056 KB
testcase_28 AC 653 ms
397,056 KB
testcase_29 AC 667 ms
397,056 KB
testcase_30 AC 684 ms
397,056 KB
testcase_31 AC 739 ms
397,056 KB
testcase_32 AC 819 ms
397,056 KB
testcase_33 AC 999 ms
396,928 KB
testcase_34 AC 1,349 ms
396,928 KB
testcase_35 AC 1,904 ms
397,056 KB
testcase_36 WA -
testcase_37 AC 591 ms
394,880 KB
testcase_38 AC 639 ms
394,880 KB
testcase_39 AC 628 ms
394,880 KB
testcase_40 AC 632 ms
394,880 KB
testcase_41 AC 639 ms
394,880 KB
testcase_42 AC 641 ms
394,880 KB
testcase_43 AC 635 ms
394,880 KB
testcase_44 AC 627 ms
394,880 KB
testcase_45 AC 623 ms
394,880 KB
testcase_46 AC 596 ms
394,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let (n, m): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let mut p: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    let mut world = vec![Vec::new(); n];
    for i in 0..n {
        p[i] -= 1;
        world[p[i]].push(i);
    }
    let mut friend = vec![vec![false; n]; n];
    for _ in 0..m {
        let (a, b): (usize, usize) = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap()
            )
        };
        friend[a - 1][b - 1] = true;
        friend[b - 1][a - 1] = true;
    }
    let q: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    for _ in 0..q {
        let mut flag = false;
        let (mut x, mut y): (usize, usize) = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap()
            )
        };
        x -= 1; y -= 1;
        if p[x] != p[y] {
            for &z in world[p[y]].iter() {
                if friend[x][z] {
                    flag = true;
                    break
                }
            }
        }
        if flag {
            for i in 0..world[p[x]].len() {
                if world[p[x]][i] == x {
                    world[p[x]].remove(i);
                    break
                }
            }
            world[y].push(x);
            p[x] = p[y];
            println!("Yes");
        } else {
            println!("No");
        }
    }
}
0