BZOJ2502: Cleaning the Snow trails

Source: Internet
Author: User

Exercises

Bare Nether Minimum stream. J beat into I feel life lost hope ...

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 100000 - #defineMAXM 100000 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y;i;i=e[i].next) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { -     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intN,m,s,t,ss,tt,inch[maxn],maxflow,tot=1, HEAD[MAXN],CUR[MAXN],H[MAXN]; -queue<int>Q; the structedge{intGo,next,v;} E[MAXM]; *InlinevoidInsintXintYintv) $ {Panax NotoginsengE[++tot]= (Edge) {y,head[x],v};head[x]=tot; -E[++tot]= (Edge) {X,head[y],0};head[y]=tot; the } +InlinevoidInsertintXintYintLintR) A { the     inch[Y]+=l;inch[X]-=l;ins (x,y,r-l); + } - voidbuild () $ { $For0 (I,TT)if(inch[i]>0) Ins (Ss,i,inch[i]);Else if(inch[i]<0) Ins (i,tt,-inch[i]); - } - BOOLBFS () the { -      for(intI=0; i<=tt;i++) h[i]=-1;WuyiQ.push (s); h[s]=0; the      while(!q.empty ()) -     { Wu         intx=Q.front (); Q.pop (); -          for(intI=head[x];i;i=e[i].next) About          if(e[i].v&&h[e[i].go]==-1) $          { -h[e[i].go]=h[x]+1; Q.push (e[i].go); -          } -     } A     returnh[t]!=-1; + } the intDfsintXintf) - { $     if(x==t)returnF; the     intTmp,used=0; the      for(intI=cur[x];i;i=e[i].next) the      if(e[i].v&&h[e[i].go]==h[x]+1) the     { -Tmp=dfs (E[i].go,min (e[i].v,f-used)); ine[i].v-=tmp;if(E[I].V) cur[x]=i; thee[i^1].v+=tmp;used+=tmp; the         if(used==f)returnF;  About     } the     if(!used) h[x]=-1; the     returnused; the } + voiddinic () - { themaxflow=0;Bayi      while(BFS ()) the     { the          for(intI=0; i<=tt;i++) cur[i]=head[i];maxflow+=DFS (s,inf); -     } - } the intMinflow () the { thes=ss;t=tt; the dinic (); -     intans=e[tot].v; thee[tot].v=e[tot^1].v=0; thes=n+1; t=0; the dinic ();94     returnans-Maxflow; the } the intMain () the {98Freopen ("Input.txt","R", stdin); AboutFreopen ("output.txt","W", stdout); -n=read ();101 For1 (i,n)102     {103         intx=read ();104For1 (j,x) Insert (I,read (),1, INF); the     }106s=0; t=n+1; ss=t+1; tt=t+2;107For1 (i,n) Insert (S,i,0, INF), insert (I,t,0, INF);108 build ();109Insert (T,s,0, INF); theprintf"%d\n", Minflow ()); 111     return 0; the}
View Code

2502: Clean up the snow lane time limit:10 Sec Memory limit:128 MB
submit:127 solved:67
[Submit] [Status] DescriptionThe ski slopes are located on several hills in the northwestern part of FJ province. from the aerial view, the ski slopes can be seen as a directed, non-circular map, each arc represents a slope (that is, the snow path), the direction of the arc represents the direction of the slope descent. your team is responsible for cleaning the slopes regularly every week. You have a helicopter, and each flight can take one person from headquarters to a location on the ski slopes before flying back to headquarters. From the point of landing, the man could glide down the slope and clean up the snow path he had passed. as the cost of each flight is fixed, in order to minimize the cost, you want to know how to use the minimum number of flights to complete the task of cleaning the snow. InputThe first line of the input file contains an integer N(2 <= n <= 100) – The number of locations representing the ski slopes. The next n lines describe the Slopes starting at 1~ N, and the first number of rows I is mi (0 <= mi < n) , followed by a total of mi integers, separated by spaces, each integer AIJ , representing the location i descend to the slope of the place AIJ. At least one ramp is connected to each location. Output The first line of the output file is an integer k – The minimum number of helicopters flown. Sample Input8
1 3
1 7
2 4 5
1 8
1 8
0
2 6 5
0
Sample Output4HINT Source

2011 Fujian Training

BZOJ2502: Cleaning the Snow trails

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.