@@ -14,26 +14,25 @@ const N = Number(input[0]);
1414const M = Number ( input [ 1 ] ) ;
1515const fees = input . slice ( 2 ) . map ( ( val ) => val . split ( ' ' ) . map ( Number ) ) ;
1616
17- const INF = 100001 ;
18- const graph = Array . from ( Array ( N + 1 ) , ( ) => Array ( N + 1 ) . fill ( INF ) ) ;
19-
20- for ( let i = 1 ; i <= N ; i ++ ) {
21- graph [ i ] [ i ] = 0 ;
22- }
17+ const graph = Array . from ( Array ( N + 1 ) , ( ) => Array ( N + 1 ) . fill ( Infinity ) ) ;
2318
2419for ( let i = 0 ; i < M ; i ++ ) {
2520 const [ a , b , c ] = fees [ i ] ;
2621
2722 graph [ a ] [ b ] = Math . min ( graph [ a ] [ b ] , c ) ;
2823}
2924
25+ for ( let i = 1 ; i <= N ; i ++ ) {
26+ graph [ i ] [ i ] = 0 ;
27+ }
28+
3029// k: 거쳐가는 노드, i: 출발 노드, j: 도착 노드
3130for ( let k = 1 ; k <= N ; k ++ ) {
3231 for ( let i = 1 ; i <= N ; i ++ ) {
3332 for ( let j = 1 ; j <= N ; j ++ ) {
3433 const originalRouteCost = graph [ i ] [ j ] ;
3534 const newRouteCost = graph [ i ] [ k ] + graph [ k ] [ j ] ;
36- graph [ i ] [ j ] = Math . min ( originalRouteCost , newRouteCost ) ;
35+ if ( originalRouteCost > newRouteCost ) graph [ i ] [ j ] = newRouteCost ;
3736 }
3837 }
3938}
@@ -42,7 +41,7 @@ let answer = '';
4241
4342for ( let i = 1 ; i <= N ; i ++ ) {
4443 for ( let j = 1 ; j <= N ; j ++ ) {
45- if ( graph [ i ] [ j ] === INF ) {
44+ if ( graph [ i ] [ j ] === Infinity ) {
4645 answer += '0 ' ;
4746 } else {
4847 answer += `${ graph [ i ] [ j ] } ` ;
0 commit comments