POJ 2594--treasure exploration "binary map && minimum path Overlay && point can repeat walk && transitive closure"

Source: Internet
Author: User

Treasure Exploration
Time Limit: 6000MS Memory Limit: 65536K
Total Submissions: 7343 Accepted: 3002

Description

Has a ever read any book about treasure exploration? Has the ever see any film about treasure exploration? Have you ever explored treasure? If you never has 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 Considere D Full of treasure. For fast development of technology and ill environment for human beings, EUC sends some robots to explore the treasure.
To make it easy, we use a graph, which was formed by N points (these n points be numbered from 1 to N), to represent the P Laces to be explored. And some points is connected by one-way road, which means., through the road, a robot can only move from one end to T He and end, but cannot move back. For some unknown reasons, there are no circle in this graph. The robots can 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 is on its roads, T o Explore. You should notice so the roads of the different robots may contain some point.
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.
As an icpcer, who have excellent programming skill, can your help EUC?

Input

The input would consist of several test cases. For each test case, integers n (1 <= n <=) and M (0 <= M <=) is given in the first line, Indicat ing the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains, different integers A and B, indicating there are a one-way from A to B (0 < A , B <= N). The input is terminated by a, with the zeros.

Output

For each test of the input, print a line containing the least robots needed.

Sample Input

1 02 11 22 00 0

Sample Output

112

Test instructions

Send a robot to Mars treasure, give a non-circular graph, the robot can land at any point, and then along the road to explore other points, our task is to calculate at least how many robots will be able to access all the points. Some points can be repeated.


Analysis: The problem is a rough look, a little bit the meaning of the minimum path coverage, but the Standard minimum path coverage is different, the Standard minimum path coverage problem is that each point can only walk once, the point of the subject can be repeated to go.

But we can transform the delivery closure to create a new diagram and transform it into a standard path overlay. Minimum path overlay = number of vertices of the graph – the maximum number of matches.

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 550using namespace Std;int map[ Maxn][maxn];int used[maxn];int link[maxn];int N, m;void init () {memset (map, 0, sizeof (map));}        void Getmap () {while (m--) {int A, B;        scanf ("%d%d", &a, &b);    MAP[A][B] = 1; }}void Floyd () {for (int k = 1, k <= N; ++k) for (int i = 1; I <= n; ++i) for (int j = 1; J <= N ++J) Map[i][j] = Map[i][j] | | MAP[I][K] && map[k][j];}            bool Dfs (int x) {for (int i = 1; I <= n; ++i) {if (Map[x][i] &&!used[i]) {used[i] = 1;                if (link[i] = = 1 | | DFS (LINK[I])) {link[i] = x;            return true; }}} return false;}    int Hungary () {int ans = 0;    memset (link, 1, sizeof);        for (int i = 1; I <= n; ++i) {memset (used, 0, sizeof (used));    if (Dfs (i)) ans++; } return ans;    int main () {while (scanf ("%d%d", &n, &m), n | | m) {init ();        Getmap ();        Floyd ();        int sum = Hungary ();    printf ("%d\n", n-sum); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2594--treasure exploration "binary map && minimum path Overlay && point can repeat walk && transitive closure"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.