Began to think is the longest road, thinking of each course of each lesson as a point to build a map ... And then wrote when found too many points (300*7*12) Jiantut trouble, he gave up the idea decisively.
And then began to use the elimination method to think of what algorithm is appropriate, no ring is not possible to shrink point, the source point sink is not obviously unlike the maximum flow, what the smallest generation tree ah is more impossible. That is two points, but how to divide it? I just want to output a maximum of how many courses, the answer is certainly less than or equal to n (number of courses), gives you all the time of each course, Oops! With each course to match a suitable time is it over? The maximum number of matches must be less than or equal to N.
On the Code
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <vector>5 #defineMAXN 800006 using namespacestd;7 8 intN;9vector<int>G[MAXN];Ten intLINK[MAXN],VIS[MAXN]; One A intDfsintx) - { - for(intI=0; I<g[x].size (); i++) the { - intE =G[x][i]; - if(!Vis[e]) - { +vis[e]=1; - if(link[e]==-1||DFS (Link[e])) + { Alink[e]=x; at return true; - } - } - } - return false; - } in voidSolve () - { to intsum=0; +memset (link,-1,sizeof(link)); - for(intI=1; i<=n;i++) the { *memset (Vis,0,sizeof(Vis)); $ if(Dfs (i)) sum++;Panax Notoginseng } -printf"%d\n", sum); the } + intMain () A { the while(SCANF ("%d", &n)! =EOF) + { - for(intk=1; k<=n;k++) $ g[k].clear (); $ for(intI=1; i<=n;i++) - { - intm; thescanf"%d",&m); - for(intj=1; j<=m;j++)Wuyi { the intb; -scanf"%d%d",&a,&b); WuG[i].push_back ( A* (A-1)+b); - } About } $ solve (); - } - return 0; -}
View Code
POJ2239 Two-point matching