Submission #58961326


Source Code Expand

use proconio::{input, marker::Chars};
use std::collections::VecDeque;
pub fn main() {
    input! {
        n: usize,
        m: usize,
        abm: [(usize, usize); m],
    }
    let mut graph = vec![vec![]; n];
    for (a, b) in abm {
        graph[a - 1].push(b - 1);
    }
    let now = 0;
    let mut visited = vec![false; n];
    let mut queue = VecDeque::new();

    queue.push_back((now, 0));
    visited[now] = true;
    while let Some((now, cost)) = queue.pop_front() {
        for &next in &graph[now] {
            if next == 0 {
                println!("{}", cost + 1);
                return;
            }
            if visited[next] {
                continue;
            }
            visited[next] = true;
            queue.push_back((next, cost + 1));
        }
    }
    println!("{}", -1);
}

Submission Info

Submission Time
Task D - Cycle
User macaroon
Language Rust (rustc 1.70.0)
Score 400
Code Size 848 Byte
Status AC
Exec Time 41 ms
Memory 21392 KiB

Compile Error

warning: unused import: `marker::Chars`
 --> src/main.rs:1:23
  |
1 | use proconio::{input, marker::Chars};
  |                       ^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 39
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_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 02_cycle_00.txt, 02_cycle_01.txt, 03_path_00.txt, 03_path_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 0 ms 2076 KiB
00_sample_01.txt AC 1 ms 1936 KiB
00_sample_02.txt AC 0 ms 1932 KiB
01_random_00.txt AC 23 ms 18020 KiB
01_random_01.txt AC 11 ms 9284 KiB
01_random_02.txt AC 17 ms 14756 KiB
01_random_03.txt AC 8 ms 7092 KiB
01_random_04.txt AC 25 ms 18508 KiB
01_random_05.txt AC 15 ms 10120 KiB
01_random_06.txt AC 18 ms 15404 KiB
01_random_07.txt AC 12 ms 10004 KiB
01_random_08.txt AC 23 ms 18008 KiB
01_random_09.txt AC 12 ms 9552 KiB
01_random_10.txt AC 18 ms 15420 KiB
01_random_11.txt AC 12 ms 7980 KiB
01_random_12.txt AC 23 ms 18016 KiB
01_random_13.txt AC 10 ms 9068 KiB
01_random_14.txt AC 19 ms 15172 KiB
01_random_15.txt AC 11 ms 9616 KiB
01_random_16.txt AC 24 ms 17948 KiB
01_random_17.txt AC 8 ms 8536 KiB
01_random_18.txt AC 22 ms 17196 KiB
01_random_19.txt AC 9 ms 7956 KiB
01_random_20.txt AC 24 ms 18304 KiB
01_random_21.txt AC 17 ms 13780 KiB
01_random_22.txt AC 20 ms 15356 KiB
01_random_23.txt AC 7 ms 7328 KiB
01_random_24.txt AC 23 ms 17828 KiB
01_random_25.txt AC 16 ms 11816 KiB
01_random_26.txt AC 23 ms 16784 KiB
01_random_27.txt AC 13 ms 10100 KiB
01_random_28.txt AC 25 ms 18216 KiB
01_random_29.txt AC 16 ms 10436 KiB
01_random_30.txt AC 16 ms 14304 KiB
01_random_31.txt AC 9 ms 7488 KiB
02_cycle_00.txt AC 35 ms 21380 KiB
02_cycle_01.txt AC 41 ms 21392 KiB
03_path_00.txt AC 20 ms 21256 KiB
03_path_01.txt AC 28 ms 21364 KiB