poj2594(二分图,最小路径覆盖变形)
生活随笔
收集整理的這篇文章主要介紹了
poj2594(二分图,最小路径覆盖变形)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Treasure Exploration
Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure.?
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point.?
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.?
As an ICPCer, who has excellent programming skill, can your help EUC?
| Time Limit:?6000MS | ? | Memory Limit:?65536K |
| Total Submissions:?7611 | ? | Accepted:?3126 |
Description
Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings to you.?Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure.?
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point.?
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.?
As an ICPCer, who has excellent programming skill, can your help EUC?
Input
The input will consist of several test cases. For each test case, two integers N (1 <= N <= 500) and M (0 <= M <= 5000) are given in the first line, indicating the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains two different integers A and B, indicating there is a one-way from A to B (0 < A, B <= N). The input is terminated by a single line with two zeros.Output
For each test of the input, print a line containing the least robots needed.Sample Input
1 0 2 1 1 2 2 0 0 0Sample Output
1 1 2題意:有很多機(jī)器人和1個(gè)圖,每個(gè)機(jī)器人從該圖的一個(gè)點(diǎn)出發(fā),然后現(xiàn)在要求機(jī)器人走遍所有的點(diǎn),求最小的機(jī)器人的數(shù)量。(2個(gè)機(jī)器人可以從不同方向走過同一點(diǎn))。
思路:顯然相當(dāng)于求最路徑覆蓋嘛,只不過就是最小路徑覆蓋是每個(gè)點(diǎn)不能被走兩次的,而現(xiàn)在可以走兩次了,所以想一個(gè)辦法就是把本身不能走的點(diǎn)連起來,比如一個(gè)機(jī)器人能從a->b->c,可是現(xiàn)在b已經(jīng)被另一個(gè)機(jī)器人走過了,最短路徑覆蓋又不能讓一個(gè)點(diǎn)被兩個(gè)人走,可是該機(jī)器人必須從a->c才是最優(yōu)解,所有用floyd將所有點(diǎn)有聯(lián)系的都連接起來,這樣子仍然是原來的最小路徑覆蓋的問題了。
轉(zhuǎn)載于:https://www.cnblogs.com/martinue/p/5490459.html
總結(jié)
以上是生活随笔為你收集整理的poj2594(二分图,最小路径覆盖变形)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET页面的字符编码设置
- 下一篇: 五子棋AI循序渐进【1】实现界面和位棋盘