public static void main ( String [ ] $ ) {
  int n = scanner . nextInt ( ) , m = scanner . nextInt ( ) , a [ ] = new int [ m ] , b [ ] = new int [ m ] , num [ ] = new int [ n + 1 ] ;
  long [ ] ans = new long [ m ] ;
  fa = IntStream . rangeClosed ( 0 , n ) . toArray ( ) ;
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    a [ i ] = scanner . nextInt ( ) ;
    b [ i ] = scanner . nextInt ( ) ;
  }
  Arrays . fill ( num , 1 ) ;
  ans [ m - 1 ] = ( long ) n * ( n - 1 ) / 2 ;
  for ( int i = m - 1 ;
  i > 0 ;
  i -- ) {
    ans [ i - 1 ] = ans [ i ] ;
    if ( fd ( a [ i ] ) != fd ( b [ i ] ) ) {
      ans [ i - 1 ] -= num [ fa [ a [ i ] ] ] * num [ fa [ b [ i ] ] ] ;
      num [ fa [ b [ i ] ] ] += num [ fa [ a [ i ] ] ] ;
      fa [ fa [ a [ i ] ] ] = fa [ b [ i ] ] ;
    }
  }
  Arrays . stream ( ans ) . forEach ( System . out :: println ) ;
}

public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , m = scanner . nextInt ( ) , a [ ] = new int [ m ] , b [ ] = new int [ m ] , num [ ] = new int [ n + 1 ] ; long [ ] ans = new long [ m ] ; fa = IntStream . rangeClosed ( 0 , n ) . toArray ( ) ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; b [ i ] = scanner . nextInt ( ) ; } Arrays . fill ( num , 1 ) ; ans [ m - 1 ] = ( long ) n * ( n - 1 ) / 2 ; for ( int i = m - 1 ; i > 0 ; i -- ) { ans [ i - 1 ] = ans [ i ] ; if ( fd ( a [ i ] ) != fd ( b [ i ] ) ) { ans [ i - 1 ] -= num [ fa [ a [ i ] ] ] * num [ fa [ b [ i ] ] ] ; num [ fa [ b [ i ] ] ] += num [ fa [ a [ i ] ] ] ; fa [ fa [ a [ i ] ] ] = fa [ b [ i ] ] ; } } Arrays . stream ( ans ) . forEach ( System . out :: println ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list)))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (binary_expression left: (cast_expression type: (integral_type) value: (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (method_invocation name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))) right: (array_access array: (identifier) index: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))) right: (array_access array: (identifier) index: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))) right: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))))))))) (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_reference (field_access object: (identifier) field: (identifier)) (identifier)))))))