Created
May 14, 2022 11:14
-
-
Save chungquantin/7e460d10e2396dff43ff751055aa44c0 to your computer and use it in GitHub Desktop.
Adjacent Matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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