• [1033] Mars city

  • 时间限制: 3000 ms 内存限制: 65535 K
  • 问题描述
  • Year Many people left Earth and built some cities on Mars. Currently there are N cities, some of which are connected by narrow one-way roads. The president of Mars has decided to build police stations throughout the Mars. Given the cost of building police stations at each city, we cannot build them at all cities, due to the financial deficit. The only requirement is that every city must be reachable from some police station by roads. They expect the cost of all stations as low as possible.
  • 输入
  • The first line for each case contains two integers n, m(0 < n <= 5,000. 0 < m <= 100,000),
    the number of cities and roads. The follows n lines each contains two integers, i, c
    ( 0 < i <= n . 0 < c <=10,000 ), c represents the cost of building a police station in city i ,
    The next m lines each contains two integers u and v ( 0 < u, v <= n), indicating that there is
    a road form u to v .
  • 输出
  • For each test case, print the minimum cost of stations
  • 样例输入
  • 4 5
    1 5
    3 2
    4 9
    2 6
    1 2
    2 3
    3 4
    1 4
    4 3
    
  • 样例输出
  • 5
    
  • 提示
  • 来源
  • FZU 2006 ICPC Qualification Round I
  • 操作

显示春菜