BZOJ2535 [Noi2010]plane Aviation Control 2

Source: Internet
Author: User

During the description Expo, Shanghai's air traffic volume exceeded peacetime, and the attendant air traffic control also occurred frequently. Recently, little X was delayed more than two hours at the airport for two consecutive times because of air control. For this, small x is very dissatisfied. On the way to Yantai, small x Unfortunately once again encountered air control. So little X began to think about the issue of air traffic control. Assume that there are currently delayed flights of N, numbered 1 to N. The airport has only one takeoff runway, and all flights need to take off in a certain order (call this sequence a take-off sequence). Define the departure sequence of a flight as the flight's location in the take-off series, which is the first flight. There are two types of restrictions in the take-off sequence:? First Class (the latest departure time limit): Flight number I is not more than Ki; Class II (relative takeoff order limit): There are some relative takeoff order restrictions (A, B), indicating that flight A's departure time must be earlier than Flight B, that is, flight A's departure sequence number must be less than Flight B's departure number. The first question in small X's thinking is whether a feasible takeoff sequence can be computed given the two types of constraints. The second question is how to find out the minimum number of departures for each flight in all feasible take-off sequences, considering two types of constraints. The first line of input contains two positive integers n and m,n represents the number of flights, and m represents the number of the second class of restrictions (relative to the takeoff order limit). The second line contains n positive integers k1, K2, ", kn. The next m line, two positive integers a and b per line, represents a pair of relative takeoff order limits (A, b), where 1≤a,b≤n indicates that flight a must take off before flight B. Output

consists of two lines.
The first line contains n integers, representing a viable take-off sequence, with two adjacent integers separated by a space.
The input data guarantees that there is at least one feasible takeoff sequence. If there are many feasible schemes, the loss of
Meaning one can.
The second line contains n integers t1, T2, ", TN, where TI represents the smallest possible departure sequence for a flight I
, the adjacent two integers are separated by a space.

Sample Input5 5
4 5 2) 5 4
1 2
3 2
5 1
3 4
3 1Sample Output3 5 1) 4 2
3 4 1) 2 1HINT Source

Acknowledgement Benz

Positive solution: Topological sorting + greedy problem Solving report: Just like that one, go BZOJ2109
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN = .; + Const intMAXM =10011; A intn,m; at intW[MAXN]; - intFIRST[MAXN],NEXT[MAXM],TO[MAXM]; - intecnt; - BOOLVIS[MAXN]; - inttop; - intDUI[MAXN]; in intMP[MAXN][MAXN]; -  to structljh{ +     intVal,jilu; - }A[MAXN]; the  *InlineintGetint () $ {Panax Notoginseng        intw=0, q=0; -        CharC=GetChar (); the         while((c<'0'|| C>'9') && c!='-') c=GetChar (); +        if(c=='-') q=1, c=GetChar (); A         while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); the        returnQ? -w:w; + } -  $InlinevoidLinkintXintY) {next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y;} $  -InlinevoidTopo_sort (intx) {  -vis[x]=1; the      for(intI=first[x];i;i=Next[i]) { -     intv=To[i];Wuyi     if(!Vis[v]) { the         //w[v]=min (w[v],w[x]-1); - Topo_sort (v); Wu     } -     }   Aboutdui[++top]=x; $ }  -  -InlineBOOLCMP (LJH q,ljh QQ) {returnq.val<Qq.val;} -  AInlinevoidMake () { +      for(inti=n;i>=1; i--) { the     intu=Dui[i]; -      for(intj=first[u];j;j=Next[j]) { $W[to[j]]=min (w[u]-1, W[to[j]]); the     } the     } the  the      for(intI=1; i<=n;i++) a[i].val=w[i],a[i].jilu=i; -Sort (A +1, a+n+1, CMP); in      for(intI=1; i<=n;i++) { theprintf"%d", A[i].jilu); the     } Aboutprintf"\ n"); the } the  theInlinevoidDfsintXintNow ) { +vis[now]=1; -mp[x][now]=1; the      for(intI=first[now];i;i=Next[i]) {Bayi     intv=To[i]; the     if(!Vis[v]) {         the DFS (X,V); -     } -     } the } the  theInlinevoidGointx) { the     intj=N; -      for(inti=n;i>=1; i--){ the     intv=A[i].jilu; the     if(mp[x][v]==0&& w[v]>=j) j--; the     Else if(W[V]&LT;J) Break;94     } theprintf"%d", j); the } the 98InlinevoidWork () { AboutN=getint (); m=getint (); -      for(intI=1; i<=n;i++) w[i]=getint ();101     intx, y;102      for(intI=1; i<=m;i++) {103X=getint (); y=getint ();104 link (y,x); the     }106      for(intI=1; i<=n;i++)if(!Vis[i]) topo_sort (i);107 Make ();108      for(intI=1; i<=n;i++) memset (Vis,0,sizeof(Vis)), DFS (i,i);109      for(intI=1; i<=n;i++) Go (i); the }111  the intMain ()113 { the Work (); the   return 0; the}

BZOJ2535 [Noi2010]plane Aviation Control 2

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.