began to read the question did not understand test instructions, thought is covered, but how to pay the wrong ... I was angry, the results went to Baidu to find the grandmother of the robot can be isolated point of view, such as 1->2->3, 2->4, 5->2 this figure I now 5 matching 2,2 match 4, then 1 and 3 is left, the result is the need for three robots. But this is contrary to test instructions, the proposed request can be a little yearning, that is to say 1 can see 3, then 1 and 3 can also be matched, so the answer is 2. (There is a difference between the matching of the graph and the non-graph)
Then the next task is simple, I put all the indirect points of arrival into a direct arrival, let him go casually match well, the answer must be right.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <vector>5 #defineMAXN 5106 7 using namespacestd;8 9vector<int>G[MAXN];Ten intGROUP[MAXN][MAXN]; One intLINK[MAXN],VIS[MAXN]; A intn,m; - - intDfsintx) the { - for(intI=0; I<g[x].size (); i++) - { - intE=G[x][i]; + if(!Vis[e]) - { +vis[e]=1; A if(link[e]==-1||DFS (Link[e])) at { -link[e]=x; - return true; - } - } - } in return false; - } to voidFloyd () + { - for(intI=1; i<=n;i++) the { * for(intj=1; j<=n;j++) $ {Panax Notoginseng for(intk=1; k<=n;k++) - { the if(group[k][i]&&group[i][j]&&j!=k) group[k][j]=1; + } A } the } + } - voidSetup_map () $ { $ for(intI=1; i<=n;i++) - { - for(intj=1; j<=n;j++) the { - if(Group[i][j])Wuyi G[i].push_back (j); the } - } Wu } - intMain () About { $ while(SCANF ("%d%d", &n,&m)! =EOF) - { - if(n==0&&m==0) Break; - for(intI=1; i<=n;i++) A g[i].clear (); +memset (Group,0,sizeof(group)); the for(intj=1; j<=m;j++) - { $ intb; thescanf"%d%d",&a,&b); thegroup[a][b]=1; the } the Floyd (); - Setup_map (); inmemset (link,-1,sizeof(link)); the intsum=0; the for(intq=1; q<=n;q++) About { thememset (Vis,0,sizeof(Vis)); the if(DFS (q)) sum++; the } +printf"%d\n", N-sum); - } the return 0;Bayi}
View Code
POJ2594 inflection point bend of two points