Search (DLX): HDU 3663 Power Stations

Source: Internet
Author: User

Power Stations

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2164 Accepted Submission (s): 626
Special Judge


Problem Descriptionthere is N towns in our country, and some of them is connected by electricity cables. It is known this every town owns a power station. When a town's power station begins-work, it'll provide electric power for this town and the neighboring towns which a Re connected by cables directly. However, there is some strange bugs in the electric System–one town can only receive electric power from No to more than on E power station, otherwise the cables is burned out for overload.

The power stations cannot work all the time. The There is an available time range. For example, the power station located in Town 1 is available from the third day to the fifth day, while the Power STA tion on 2 is available from the first day to the Forth day. You can choose a sub-range of the available range as the same as the working time for each station. Note that you can be choose one sub-range for each available range, that's, once the station stops working, and you cannot Restart it again. Of course, it is possible does not have use of any of them.

Now is given all the information about the cable connection between the towns, and all the power stations ' available Time. You need to find out a schedule this every town would get the electricity supply for next D days, one and only one supplier For one town at any time.

Inputthere is several test cases. The first line of all test case contains three integers, N, M and D (1 <= N <=, 1 <= M <=, 1 <= D & Lt;= 5), indicating the number of towns is N, the number of cables are M, and you should plan for the next D days.

Each of the next M lines contains-integers a, B (1 <= A, b <= N), which means, A and town B is connect Ed directly. Then N lines followed, each contains, numbers si and Ei, (1 <= si <= ei <= D) indicating that the available TI Me of town I's power station is from the si-th day to the ei-th Day (inclusive).

Outputfor Each test case, if the plan exists, output N lines. The i-th line should contain II integers UI and VI, indicating that town I's power station should work from the ui-th day to Vi-day (inclusive). If you didn ' t use the this power station at all, set UI = VI = 0.

If the plan doesn ' t exist, output one line contains "No solution" instead.

Note that the answer is unique. Any correct answers'll be OK.

Output a blank line after each case.

Sample INPUT3 3 51 22 33 11 51 51 54 4 51 22 33 44 11 51 51 51 5

Sample Output 1 0 No solution it is not to see the problem caused WA1 hair.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn=5010;6 Const intMaxnode=1000010;7 intS[MAXN],T[MAXN],BELONG[MAXN],ANS[MAXN];8 structdlx{9     intL[maxnode],r[maxnode],u[maxnode],d[maxnode];Ten     intCNT,ROW[MAXNODE],COL[MAXNODE],C[MAXN],H[MAXN]; One     voidInit (intNintm) { A          for(intI=0; i<=m;i++){ -l[i]=i-1; r[i]=i+1; -U[i]=d[i]=i; c[i]=0; the         } -Cnt=m; l[0]=m; r[m]=0; -          for(intI=1; i<=n;i++) h[i]=0;  -     } +      -     voidLink (intRintc) { +Row[++cnt]=r; c[col[cnt]=c]+=1; A  atU[CNT]=C;D[CNT]=D[C]; u[d[c]]=cnt;d[c]=CNT; -  -         if(! H[R]) h[r]=l[cnt]=r[cnt]=CNT; -         Elser[cnt]=r[h[r]],l[cnt]=h[r],l[r[cnt]]=cnt,r[l[cnt]]=CNT; -     } -      in     voidDelete (intc) { -L[R[C]]=L[C]; r[l[c]]=R[c]; to          for(intI=d[c];i!=c;i=D[i]) +              for(intj=r[i];j!=i;j=R[j]) ---c[col[j]],u[d[j]]=u[j],d[u[j]]=D[j]; the     } *      $     voidResume (intc) {Panax NotoginsengL[r[c]]=c; r[l[c]]=C; -          for(intI=u[c];i!=c;i=U[i]) the              for(intj=l[i];j!=i;j=L[j]) +++c[col[j]],u[d[j]]=j,d[u[j]]=J; A     } the      +     BOOLSolve () { -         if(! r[0])return true; $         intp=r[0]; $          for(intI=r[p];i;i=R[i]) -             if(c[p]>C[i]) -p=i; the          - Delete (p);Wuyi          for(intI=d[p];i!=p;i=D[i]) { the             if(Ans[belong[row[i]])Continue; -              for(intj=r[i];j!=i;j=R[j]) Wu Delete (Col[j]); -                  Aboutans[belong[row[i]]]=Row[i]; $             if(Solve ()) -                 return true; -ans[belong[row[i]]]=0; -              for(intj=l[i];j!=i;j=L[j]) A Resume (Col[j]); +         } the Resume (p); -         return false;  $     } the }DLX; the  the intL[MAXN],R[MAXN]; the BOOLG[MAXN][MAXN]; -  in intMain () { the     intA,b,n,m,d,tot; the      while(SCANF ("%d%d%d", &n,&m,&d)! =EOF) { Aboutmemset (G,0,sizeof(G)); the          while(m--){ thescanf"%d%d",&a,&b); theg[a][b]=true; +g[b][a]=true; -         } the         Bayitot=0; the          for(intI=1; i<=n;i++){ thescanf"%d%d",&s[i],&t[i]); -tot+= (t[i]-s[i]+1) * (t[i]-s[i]+2)/2; -g[i][i]=true; the         } the          theDlx. Init (tot,n*D); thememset (ans,0,sizeof(ans)); -          for(intx=1, p=0; x<=n;x++) the              for(intl=s[x];l<=t[x];l++) the                  for(intr=l;r<=t[x];r++){ the++p; L[p]=l; r[p]=r;belong[p]=x;94                      for(intj=l;j<=r;j++) the                          for(inty=1; y<=n;y++) the                             if(G[x][y]) DLX. Link (J-p,n*1)+y); the                 }98         if(DLX. Solve ()) { About              for(intI=1; i<=n;i++) -printf"%d%d\n", L[ans[i]],r[ans[i]]);101         }102         Else103printf"No solution\n");104printf"\ n");  the     }    106     return 0; 107}

Search (DLX): HDU 3663 Power Stations

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.