• [1143] Irrigation of Farmland

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • Hungar has bought some farms.There is a river near the farm. It was found that linking these farms is more conducive for hungar. Therefore, he need to calculate that the minimum number of waterway he should build to connect all the farms, either connecting directly or not directly.There is not existing a waterway between river and farm,so you should also connecting them.
  • 输入
  • Input until EOF.
    For each case:
    First line: two non-negative integers M (1<=M<= 500) and N(1<=N<=500), M means the number of farms, from 1 to M.
    The next N lines: each line have two numbers A, B represents the existing waterway number.
  • 输出
  • Print the number of waterway in one line.
  • 样例输入
  • 4 2
    1 3
    4 3
    2 2
    1 2
    1 2
    
  • 样例输出
  • 2
    1
    
  • 提示
  • 来源
  • hungar
  • 操作

显示春菜