Submission #42070688


Source Code Expand

#[allow(unused_imports)]
use petgraph::unionfind::UnionFind;
#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars, marker::Usize1};
#[allow(unused_imports)]
use std::collections::{HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        n:usize , m:usize ,
        ab:[(Usize1 , Usize1);m],
    }
    if n != m {
        println!("No");
        return;
    }
    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    let mut uf = UnionFind::new(n);
    for (a, b) in ab {
        uf.union(a, b);
        g[a].push(b);
        g[b].push(a);
    }
    let mut q = uf.clone().into_labeling();
    let s = q.clone();
    q.sort();
    q.dedup();
    let mut v: Vec<usize> = vec![0; q.len()];
    for i in 0..n {
        let a = q.binary_search(&(uf.find(i))).unwrap();
        v[a] += g[i].len();
    }
    for i in 0..q.len() {
        if (v[i] / 2) != s.iter().filter(|&&x| x == q[i]).count() {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Submission Info

Submission Time
Task D - Unicyclic Components
User sou31415
Language Rust (1.42.0)
Score 400
Code Size 1001 Byte
Status AC
Exec Time 88 ms
Memory 21744 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 61
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 02_one_00.txt, 02_one_01.txt, 02_one_02.txt, 02_one_03.txt, 02_one_04.txt, 02_one_05.txt, 02_one_06.txt, 02_one_07.txt, 02_one_08.txt, 02_one_09.txt, 02_one_10.txt, 02_one_11.txt, 02_one_12.txt, 02_one_13.txt, 03_two_00.txt, 03_two_01.txt, 03_two_02.txt, 03_two_03.txt, 03_two_04.txt, 03_two_05.txt, 03_two_06.txt, 03_two_07.txt, 03_two_08.txt, 03_two_09.txt, 03_two_10.txt, 03_two_11.txt, 04_many_00.txt, 04_many_01.txt, 04_many_02.txt, 04_many_03.txt, 04_many_04.txt, 04_many_05.txt, 04_many_06.txt, 04_many_07.txt, 04_many_08.txt, 04_many_09.txt, 04_many_10.txt, 04_many_11.txt, 05_hand_00.txt, 05_hand_01.txt, 99_hack_00.txt, 99_hack_01.txt, 99_hack_02.txt, 99_hack_03.txt, 99_hack_04.txt, 99_hack_05.txt, 99_hack_06.txt, 99_hack_07.txt, 99_hack_08.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 2060 KiB
00_sample_01.txt AC 2 ms 2084 KiB
00_sample_02.txt AC 1 ms 2112 KiB
01_rnd_00.txt AC 1 ms 2112 KiB
01_rnd_01.txt AC 1 ms 2060 KiB
01_rnd_02.txt AC 17 ms 5796 KiB
01_rnd_03.txt AC 1 ms 2096 KiB
01_rnd_04.txt AC 1 ms 2192 KiB
01_rnd_05.txt AC 20 ms 6608 KiB
01_rnd_06.txt AC 3 ms 1968 KiB
01_rnd_07.txt AC 1 ms 2116 KiB
01_rnd_08.txt AC 88 ms 21744 KiB
02_one_00.txt AC 2 ms 2032 KiB
02_one_01.txt AC 1 ms 2188 KiB
02_one_02.txt AC 2 ms 2052 KiB
02_one_03.txt AC 1 ms 2064 KiB
02_one_04.txt AC 1 ms 2064 KiB
02_one_05.txt AC 1 ms 2164 KiB
02_one_06.txt AC 1 ms 2112 KiB
02_one_07.txt AC 31 ms 6908 KiB
02_one_08.txt AC 23 ms 6988 KiB
02_one_09.txt AC 67 ms 20040 KiB
02_one_10.txt AC 69 ms 20108 KiB
02_one_11.txt AC 70 ms 19960 KiB
02_one_12.txt AC 69 ms 19172 KiB
02_one_13.txt AC 25 ms 6976 KiB
03_two_00.txt AC 71 ms 20008 KiB
03_two_01.txt AC 68 ms 19532 KiB
03_two_02.txt AC 69 ms 20048 KiB
03_two_03.txt AC 69 ms 20028 KiB
03_two_04.txt AC 68 ms 19844 KiB
03_two_05.txt AC 68 ms 19668 KiB
03_two_06.txt AC 69 ms 20032 KiB
03_two_07.txt AC 71 ms 19968 KiB
03_two_08.txt AC 67 ms 19668 KiB
03_two_09.txt AC 68 ms 19892 KiB
03_two_10.txt AC 75 ms 19628 KiB
03_two_11.txt AC 68 ms 19240 KiB
04_many_00.txt AC 47 ms 15264 KiB
04_many_01.txt AC 18 ms 5664 KiB
04_many_02.txt AC 17 ms 5672 KiB
04_many_03.txt AC 44 ms 15332 KiB
04_many_04.txt AC 69 ms 19876 KiB
04_many_05.txt AC 26 ms 6908 KiB
04_many_06.txt AC 25 ms 6944 KiB
04_many_07.txt AC 67 ms 19820 KiB
04_many_08.txt AC 62 ms 18744 KiB
04_many_09.txt AC 20 ms 6884 KiB
04_many_10.txt AC 22 ms 6948 KiB
04_many_11.txt AC 64 ms 18704 KiB
05_hand_00.txt AC 2 ms 1984 KiB
05_hand_01.txt AC 53 ms 20088 KiB
99_hack_00.txt AC 1 ms 2064 KiB
99_hack_01.txt AC 1 ms 2168 KiB
99_hack_02.txt AC 1 ms 2016 KiB
99_hack_03.txt AC 1 ms 2064 KiB
99_hack_04.txt AC 1 ms 1980 KiB
99_hack_05.txt AC 1 ms 2100 KiB
99_hack_06.txt AC 1 ms 2172 KiB
99_hack_07.txt AC 1 ms 2068 KiB
99_hack_08.txt AC 2 ms 1988 KiB