"Network Stream 24 Questions----02" Air RAID Minimum Path overlay

Source: Internet
Author: User

Air Raid

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4591 Accepted Submission (s): 3072


Problem Descriptionconsider a town where all the streets is one-way and each street leads from one intersection to Anothe R. It is also known, starting from a intersection and walking through town's streets you can never reach the same int Ersection 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.

Inputyour 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.

Outputthe 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 Input2433 41 32 3331 31 22 3

Sample Output21 The translation is:

A town has a path of n intersections and M items, and the graph is a graph without a loop.

Some paratroopers can start at any intersection and ask for a disjoint path and reach all intersections;

Our task is to find a minimum number of paratroopers.

So it is clear that the minimum path coverage problem is (what do you not do with minimal path coverage?). )

Examples:

4 3

1 3

2 3

3 4

Figure One (example)

Figure II (converted to two-minute chart)

Then: the minimum path of the graph is covered =v-the maximum matching of the binary graph.

Code: I'm still running dinic.

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstdlib>5#include <algorithm>6#include <vector>7#include <cstring>8 #defineYyj (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout);9 #defineLLG Long LongTen #defineMAXN 2000 One LLG J,k,n,m,y,z,bj[maxn],head,tail,dl[maxn],deep[maxn],ans; A BOOLf,ff; - using namespacestd; -Vector <llg>A[MAXN],V[MAXN],BA[MAXN]; the //A[I][J] indicates that the first point points to the J Point is a[i][j],v[i][j] (traffic), Ba[i][j] a[i][j] of the anti-Xiangbian - llg DFS (llg x,llg low) - { -LLG res=0; LLG va=0; +     if(x==n) {returnLow ;} -LLG w=a[x].size (); +      for(Llg i=0; i<w;i++) A         if(deep[x]+1==deep[a[x][i]] && v[x][i]>0&& (va=Dfs (a[x][i],min (low,v[x][i )))) at         { -V[x][i]-=va; v[a[x][i]][ba[x][i]]+=va; -             returnva; -         } -     return 0; - } in voidFencen () - { tomemset (BJ,0,sizeof(BJ)); +Tail=1; Head=0; dl[1]=0; bj[0]=1; -          Do{ thehead++; *LLG x=Dl[head]; $LLG w=a[x].size ();Panax Notoginseng              for(Llg i=0; i<w;i++) -                 if(!bj[a[x][i]] && v[x][i]>0) the                 { +tail++; dl[tail]=A[x][i]; Adeep[a[x][i]]=deep[x]+1; thebj[a[x][i]]=1; +                 } -} while(head!=tail); $ } $ voidInsert (llg x,llg y,llg z) - { - a[x].push_back (y); V[x].push_back (z); theA[y].push_back (x); V[y].push_back (0); -Ba[x].push_back (A[y].size ()-1); Ba[y].push_back (A[x].size ()-1);Wuyi } the intMain () - { WuYyj"a"); -cin>>n>>m; deep[0]=1; About      for(Llg i=1; i<=m;i++) $     { - LLG x; -Cin>>x>>y; -Insert (x*2-1, y*2,1); Insert (x*2, y*2-1,0); A     } +      for(Llg i=1; i<=n;i++) the     { -Insert0, i*2-1,1); Insert (i*2-1,0,0); $Insert (i*2N2+1,1); Insert (n2+1, i*2,0); the     } theLLG total=N; then=n*2+1; the      while(1) -     { inf=true; ff=false; the Fencen (); the         if(!bj[n]) Break; AboutAns+=dfs (0,0x7fffffff); the     } thecout<<total-ans<<Endl; the     return 0; +}

Say a few words:

Remember where you hit the red mark in the dry. "Disjoint paths"

  What if we could intersect? Then we're going to run it again. floyed closures were passed.

What, you're not clear. (Take a look at http://www.cnblogs.com/ka200812/archive/2011/07/31/2122641.html yourself)
  Photo from: http://www.cppblog.com/zhangwangcz/archive/2012/03/30/155686.html

"Network Stream 24 Questions----02" Air RAID 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.