Submission #63283195


Source Code Expand

Copy
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
use ac_library::*;
use once_cell::sync::Lazy;
use static_assertions::*;
use varisat::*;
use memoise::*;
use argio::*;
use bitvec::prelude::*;
use counter::Counter;
use hashbag::*;
use pathfinding::prelude::*;
use recur_fn::*;
use ::indexing::*;
use amplify::*;
use amplify_derive::*;
use amplify_num::*;
use easy_ext::*;
use multimap::*;
use btreemultimap::*;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
use ac_library::*;
use once_cell::sync::Lazy;
use static_assertions::*;
use varisat::*;
use memoise::*;
use argio::*;
use bitvec::prelude::*;
use counter::Counter;
use hashbag::*;
use pathfinding::prelude::*;
use recur_fn::*;
use ::indexing::*;
use amplify::*;
use amplify_derive::*;
use amplify_num::*;
use easy_ext::*;
use multimap::*;
use btreemultimap::*;
use bstr::*;
use az::*;
use glidesort::*;
use ::tap::*;
use omniswap::*;
use multiversion::*;
use ::num::*;
use num_bigint::*;
use num_complex::*;
use num_integer::*;
use num_iter::*;
use num_rational::*;
use num_traits::*;
use num_derive::*;
use ndarray::*;
use nalgebra::*;
use alga::*;
use libm::*;
use rand::*;
use getrandom::*;
use rand_chacha::*;
use rand_core::*;
use rand_hc::*;
use rand_pcg::*;
use rand_distr::*;
use petgraph::graph::{DiGraph, UnGraph};
use indexmap::*;
use regex::*;
use lazy_static::*;
use ordered_float::*;
use ascii::*;
use permutohedron::*;
use superslice::*;
use itertools::*;
use itertools_num::*;
use maplit::*;
use either::*;
use im_rc::*;
use fixedbitset::*;
use bitset_fixed::*;
use proconio::input;
use proconio::marker::{Bytes, Chars, Usize1};
use text_io::*;
use rustc_hash::*;
use smallvec::*;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, BinaryHeap};

fn main() {
    input! {
        N: usize,
        M: usize,
        X: usize,
    }

    let ans = solve(N, M, X);
    println!("{}", ans);
}

fn solve(N: usize, M: usize, X: usize) -> usize {
    input! {
        uv: [(Usize1, Usize1); M],
    }

    let mut original = DiGraph::<(), ()>::new();
    let mut reversed = DiGraph::<(), ()>::new();

    for _ in 0..N {
        original.add_node(());
        reversed.add_node(());
    }

    for &(u, v) in &uv {
        original.add_edge(original.node_indices().nth(u).unwrap(),
                          original.node_indices().nth(v).unwrap(), ());
        reversed.add_edge(reversed.node_indices().nth(v).unwrap(),
                          reversed.node_indices().nth(u).unwrap(), ());
    }

    let mut dist = vec![vec![usize::MAX; 2]; N];
    let mut queue = BinaryHeap::new();

    dist[0][0] = 0;
    queue.push(std::cmp::Reverse((0, 0, 0)));

    while let Some(std::cmp::Reverse((cost, node, state))) = queue.pop() {
        if node == N - 1 {
            return cost;
        }

        if cost > dist[node][state] {
            continue;
        }

        let cur = if state == 0 { &original } else { &reversed };
        let node_i = cur.node_indices().nth(node).unwrap();

        for neighbor in cur.neighbors(node_i) {
            let next_node = neighbor.index();
            let next_cost = cost + 1;

            if next_cost < dist[next_node][state] {
                dist[next_node][state] = next_cost;
                queue.push(std::cmp::Reverse((next_cost, next_node, state)));
            }
        }

        let next_state = 1 - state;
        let next_cost = cost + X;

        if next_cost < dist[node][next_state] {
            dist[node][next_state] = next_cost;
            queue.push(std::cmp::Reverse((next_cost, node, next_state)));
        }
    }
    unreachable!();
}

Submission Info

Submission Time
Task E - Flip Edge
User maysay_d
Language Rust (rustc 1.70.0)
Score 425
Code Size 3208 Byte
Status AC
Exec Time 127 ms
Memory 32692 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 4
AC × 70
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_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, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt, 01_random_69.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1972 KB
00_sample_01.txt AC 1 ms 1808 KB
00_sample_02.txt AC 1 ms 2004 KB
00_sample_03.txt AC 1 ms 2036 KB
01_random_04.txt AC 51 ms 29196 KB
01_random_05.txt AC 116 ms 28660 KB
01_random_06.txt AC 86 ms 27956 KB
01_random_07.txt AC 93 ms 29488 KB
01_random_08.txt AC 73 ms 28812 KB
01_random_09.txt AC 91 ms 27996 KB
01_random_10.txt AC 26 ms 28024 KB
01_random_11.txt AC 98 ms 28768 KB
01_random_12.txt AC 38 ms 27836 KB
01_random_13.txt AC 50 ms 29096 KB
01_random_14.txt AC 59 ms 28740 KB
01_random_15.txt AC 107 ms 27948 KB
01_random_16.txt AC 37 ms 28392 KB
01_random_17.txt AC 45 ms 28396 KB
01_random_18.txt AC 127 ms 28044 KB
01_random_19.txt AC 102 ms 29704 KB
01_random_20.txt AC 66 ms 28704 KB
01_random_21.txt AC 97 ms 28012 KB
01_random_22.txt AC 35 ms 28496 KB
01_random_23.txt AC 62 ms 28644 KB
01_random_24.txt AC 75 ms 28024 KB
01_random_25.txt AC 35 ms 28424 KB
01_random_26.txt AC 90 ms 28648 KB
01_random_27.txt AC 66 ms 27920 KB
01_random_28.txt AC 38 ms 28740 KB
01_random_29.txt AC 97 ms 28748 KB
01_random_30.txt AC 41 ms 28004 KB
01_random_31.txt AC 37 ms 22528 KB
01_random_32.txt AC 18 ms 9268 KB
01_random_33.txt AC 28 ms 14644 KB
01_random_34.txt AC 32 ms 24380 KB
01_random_35.txt AC 28 ms 14960 KB
01_random_36.txt AC 32 ms 16480 KB
01_random_37.txt AC 24 ms 14912 KB
01_random_38.txt AC 16 ms 17580 KB
01_random_39.txt AC 37 ms 14784 KB
01_random_40.txt AC 59 ms 23060 KB
01_random_41.txt AC 31 ms 20980 KB
01_random_42.txt AC 8 ms 5256 KB
01_random_43.txt AC 61 ms 22948 KB
01_random_44.txt AC 21 ms 13112 KB
01_random_45.txt AC 101 ms 26808 KB
01_random_46.txt AC 64 ms 27936 KB
01_random_47.txt AC 87 ms 32692 KB
01_random_48.txt AC 56 ms 27892 KB
01_random_49.txt AC 90 ms 32632 KB
01_random_50.txt AC 41 ms 27776 KB
01_random_51.txt AC 89 ms 32632 KB
01_random_52.txt AC 53 ms 27864 KB
01_random_53.txt AC 46 ms 30324 KB
01_random_54.txt AC 34 ms 27892 KB
01_random_55.txt AC 89 ms 32524 KB
01_random_56.txt AC 66 ms 27888 KB
01_random_57.txt AC 65 ms 27728 KB
01_random_58.txt AC 64 ms 27848 KB
01_random_59.txt AC 93 ms 27908 KB
01_random_60.txt AC 94 ms 27832 KB
01_random_61.txt AC 103 ms 27844 KB
01_random_62.txt AC 43 ms 23148 KB
01_random_63.txt AC 43 ms 23200 KB
01_random_64.txt AC 43 ms 23136 KB
01_random_65.txt AC 1 ms 2048 KB
01_random_66.txt AC 1 ms 2148 KB
01_random_67.txt AC 0 ms 1868 KB
01_random_68.txt AC 9 ms 14928 KB
01_random_69.txt AC 4 ms 7540 KB


2025-04-04 (Fri)
04:16:27 +00:00