• [1129] Base of Space

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • In 2222, human has been highly developed in space. There are a lot of bases in the space. It was found that linking these bases is more conducive to human's development. Therefore, We need to calculate that the minimum number of roads we should build to connect all the bases, either connecting directly or not directly.

  • 输入
  • There are multiple cases.
    For each case:
    First line: two non-negative integers M (M <= 1000) and N, M means the number of bases, from 1 to M.
    The next N lines: each line have two numbers A, B represents the existing road number.
    when M = N = 0 means the end.
  • 输出
  • Print the number of road in one line.
  • 样例输入
  • 4 2
    1 3
    4 3
    2 2
    1 2
    1 2
    0 0
    
  • 样例输出
  • 1
    0
  • 提示
  • 来源
  • NE123123
  • 操作

显示春菜