POJ 1422 && ZOJ 1525--air Raid "binary map && minimum path overlay"

Source: Internet
Author: User

Air Raid
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 7451 Accepted: 4434

Description

Consider a town where all the streets is one-way and each of the street leads from one intersection to another. It is also known this starting from a intersection and walking through town's streets you can never reach the same inters Ection i.e. the town ' s streets Form no cycles.

With these assumptions your task was to write a program this finds the minimum number of paratroopers that can descend on t He town and visit all the intersections of this town in such a-the-more than one paratrooper visits no intersection. Each of the paratrooper lands at a intersection and can visit other intersections following the town streets. There is no restrictions about the starting intersection for each paratrooper.

Input

Your program should read sets of data. The first line of the input file contains the number of the data sets. Each data set specifies the structure of a town and have the format:

No_of_intersections
No_of_streets
S1 E1
S2 E2
......
Sno_of_streets eno_of_streets

The first line of all data set contains a positive integer no_of_intersections (greater than 0 and less or equal to 120), Which is the number of intersections in the town. The second line contains a positive integer no_of_streets, and which is the number of streets in the town. The next no_of_streets lines, one for each street in the town, is randomly ordered and represent the town ' s streets. The line corresponding to Street K (k <= no_of_streets) consists of a positive integers, separated by one blank:sk ( 1 <= Sk <= no_of_intersections)-The number of the intersection that is the start of the street, and EK (1 <= ek <= no_of_intersections)-The number of the intersection that's the end of the street. Intersections is represented by integers from 1 to no_of_intersections.

There is no blank lines between consecutive sets of data. Input data is correct.

Output

The result of the program was on standard output. For each input data set the program prints on a, starting from the beginning of the line, one integer:the min Imum number of paratroopers required to visit all the intersections in the town.

Sample Input

2433 41 32 3331 31 22 3

Sample Output

21st

Test instructions: There are n small towns on a map, and M is connected to two of the small towns with a forward edge, and these edges cannot form loops. Now choose some small town airborne soldiers (1 small towns up to 1 soldiers), soldiers can go down to the end, ask the least airborne several soldiers, can walk through all the town.


Parse: Bare can no longer bare the minimum path coverage problem, first say what is the minimum path coverage:

In a forward graph, the path overlay is to find some path in the diagram to cover all the vertices in the graph, and any one vertex has and only one path associated with it; (if each path in these paths goes from its starting point to its end, it can pass through each vertex of the diagram once and only once).

First we set up a two-point map, a city as a node, we first split a node into two nodes, divided by the left and right parts, connected nodes to build edges, to find the maximum number of matches.

The minimum path coverage of a binary graph = Two The maximum number of matches of the vertex-two graph of the graph.

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 200using namespace Std;int map[ Maxn][maxn];int used[maxn];int link[maxn];int N, m;void init () {memset (map, 0, sizeof (map));}    void Getmap () {scanf ("%d%d", &n, &m);        while (m--) {int A, B;        scanf ("%d%d", &a, &b);    MAP[A][B] = 1;            }}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 () {int T;    scanf ("%d", &t);        while (t--) {init ();        Getmap ();        int sum = Hungary ();        printf ("%d\n", sum); printf ("%d\n", N-sum); } return 0;}


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

POJ 1422 && ZOJ 1525--air Raid "binary map && minimum path overlay"

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.