Problem:
Score : 100 points

Problem Statement

It is September 9 in Japan now.

You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

Constraints

10≤N≤99

Input

Input is given from Standard Input in the following format:

N

Output

If 9 is contained in the decimal notation of N, print Yes; if not, print No.

Sample Input 1

29

Sample Output 1

Yes

The one's digit of 29 is 9.

Sample Input 2

72

Sample Output 2

No

72 does not contain 9.

Sample Input 3

91

Sample Output 3

Yes

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

use std::vec::Vec;
use std::cmp::*;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

pub trait LexicalPermutation {
    /// Return `true` if the slice was permuted, `false` if it is already
    /// at the last ordered permutation.
    fn next_permutation(&mut self) -> bool;
    /// Return `true` if the slice was permuted, `false` if it is already
    /// at the first ordered permutation.
    fn prev_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T] where T: Ord {
    /// Original author in Rust: Thomas Backman <serenity@exscape.org>
    fn next_permutation(&mut self) -> bool {
        // These cases only have 1 permutation each, so we can't do anything.
        if self.len() < 2 { return false; }

        // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
        let mut i = self.len() - 1;
        while i > 0 && self[i-1] >= self[i] {
            i -= 1;
        }

        // If that is the entire vector, this is the last-ordered permutation.
        if i == 0 {
            return false;
        }

        // Step 2: Find the rightmost element larger than the pivot (i-1)
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i-1]  {
            j -= 1;
        }

        // Step 3: Swap that element with the pivot
        self.swap(j, i-1);

        // Step 4: Reverse the (previously) weakly decreasing part
        self[i..].reverse();

        true
    }

    fn prev_permutation(&mut self) -> bool {
        // These cases only have 1 permutation each, so we can't do anything.
        if self.len() < 2 { return false; }

        // Step 1: Identify the longest, rightmost weakly increasing part of the vector
        let mut i = self.len() - 1;
        while i > 0 && self[i-1] <= self[i] {
            i -= 1;
        }

        // If that is the entire vector, this is the first-ordered permutation.
        if i == 0 {
            return false;
        }

        // Step 2: Reverse the weakly increasing part
        self[i..].reverse();

        // Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
        let mut j = self.len() - 1;
        while j >= i && self[j-1] < self[i-1]  {
            j -= 1;
        }

        // Step 4: Swap that element with the pivot
        self.swap(i-1, j);

        true
    }

}



fn warshal_floyd(n: usize, v: &Vec<(usize, usize, usize)>, direct: bool) -> Vec<Vec<usize>> {
  let mut dist = vec![vec![std::usize::MAX/3; n]; n];
  // init
  for &(x, y, c) in v {
    dist[x][y] = c;
    if !direct {
      dist[y][x] = c;
    }
  }

  for i in 0..n {
    for j in 0..n {
      for k in 0..n {
        if dist[i][j] > dist[i][k] + dist[k][j] {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
  dist
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (n, m, r) = {
    let v: Vec<usize> = read_vec();
    (v[0], v[1], v[2])
  };

  let mut v: Vec<usize> = read_vec::<usize>().iter().map(|&x| x - 1).collect();
  let mut t: Vec<(usize, usize, usize)> = Vec::new();
  for _ in 0..m {
    let s: Vec<usize> = read_vec();
    t.push((s[0] - 1, s[1] - 1, s[2]));
  }

  v.sort();
  // 各頂点の経路探索
  let dist = warshal_floyd(n, &t, false);

  let mut res = std::usize::MAX;

  while {
    let mut tmp = 0;
    for i in 1..r {
      tmp += dist[v[i-1]][v[i]];
    }
    res = min(res, tmp);
    v.next_permutation()
  } {}

  println!("{}", res);

}