public static long [ ] bellmanFord ( int n , int [ ] [ ] edge , int s ) {
  long d [ ] = new long [ n ] ;
  Arrays . fill ( d , Long . MAX_VALUE ) ;
  d [ s ] = 0L ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    for ( int j = 0 ;
    j < edge . length ;
    j ++ ) {
      int [ ] e = edge [ j ] ;
      if ( d [ e [ 0 ] ] != Long . MAX_VALUE && d [ e [ 1 ] ] > d [ e [ 0 ] ] + e [ 2 ] ) {
        d [ e [ 1 ] ] = d [ e [ 0 ] ] + e [ 2 ] ;
        if ( i == n - 1 && e [ 1 ] == n - 1 ) {
          d = null ;
          break ;
        }
      }
    }
  }
  return d ;
}

public static long [ ] bellmanFord ( int n , int [ ] [ ] edge , int s ) { long d [ ] = new long [ n ] ; Arrays . fill ( d , Long . MAX_VALUE ) ; d [ s ] = 0L ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < edge . length ; j ++ ) { int [ ] e = edge [ j ] ; if ( d [ e [ 0 ] ] != Long . MAX_VALUE && d [ e [ 1 ] ] > d [ e [ 0 ] ] + e [ 2 ] ) { d [ e [ 1 ] ] = d [ e [ 0 ] ] + e [ 2 ] ; if ( i == n - 1 && e [ 1 ] == n - 1 ) { d = null ; break ; } } } } return d ; }
(method_declaration (modifiers) type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (field_access object: (identifier) field: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))) right: (field_access object: (identifier) field: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))) right: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))) right: (array_access array: (identifier) index: (decimal_integer_literal)))))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))) right: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (decimal_integer_literal))) right: (array_access array: (identifier) index: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (null_literal))) (break_statement))))))))) (return_statement (identifier))))