Skip to content

Instantly share code, notes, and snippets.

@chungquantin
Created May 14, 2022 11:14
Show Gist options
  • Select an option

  • Save chungquantin/7e460d10e2396dff43ff751055aa44c0 to your computer and use it in GitHub Desktop.

Select an option

Save chungquantin/7e460d10e2396dff43ff751055aa44c0 to your computer and use it in GitHub Desktop.
Adjacent Matrix
fn build_adjacent_matrix(n: i32, edges: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut adjacent_m: Vec<Vec<i32>> = vec![vec![i32::MAX; n as usize]; n as usize];
for edge in edges {
let (s, t, w) = (edge[0], edge[1], edge[2]);
adjacent_m[s as usize][t as usize] = w;
}
for i in 0..n as usize {
adjacent_m[i][i] = 0;
}
adjacent_m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment