POJ2239 Two-point matching

Source: Internet
Author: User

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

Related Article

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.