Bzoj 736 [ctsc1999][Network Stream 24 questions] Interstellar transfer __ graph theory

Source: Internet
Author: User

«Problem Description:

Because of the human consumption of natural resources, people realize that about 2,300 years later, the earth can no longer live.
A new green space was set up on the moon so as to emigrate when needed. Surprisingly, the winter of 2177 was not
Know the reason, the Earth environment has a chain collapse, the human must in the shortest time inland to the moon. Existing n space stations
It is between the earth and the moon, and there are M public transport spacecraft shuttling back and forth. Each space station can accommodate unlimited
Many people, and each spacecraft I can only accommodate h[i] individuals. Each spacecraft will periodically dock a series of space stations,
For example: (1,3,4) said the spacecraft will be periodically docked to the space station 134134134 .... Every spaceship from a too
An empty station will take 1 to any space station. People can only disembark when the spacecraft is docked to the space station (or the moon, the Earth).
At the beginning all were on Earth, and the spacecraft were all at the initial station. Try to design an algorithm to find all the people as quickly as possible
Transfer to the Moon on the transport scheme.
«Programming Tasks:

For a given spacecraft's information, find a transport solution that allows everyone to move to the moon as quickly as possible.
«Data Entry:
Input data is provided by the file home.in. File line 1th has 3 positive integers n (number of space stations), M (spacecraft
Number) and K (number of people on Earth to be transported). Among them 1<=m<=20, 1<=n<=13, 1<=k<=50.
The next line of M gives information about the spacecraft. The I+1 line describes the spacecraft pi. The 1th number indicates the PI can be accommodated
Number of HPI; number 2nd represents pi. Number of space stations docked in a cycle r,1<=r<=n+2; then R number is docked
The number of the space station (SI1,SI2,..., Sir), the earth used 0, the Moon 1. Time 0 o'clock, all spaceships are
At the initial station, and then start running. At the moment 1,2,3 ... The spacecraft docked at the appropriate space station at the moment. People
Only in the 0,1,2 ... It's time to get up and down the spaceship.
«Results Output:

At the end of the program, the time required for the security transfer of all personnel is exported to the file home.out. If the problem
No solution, then output 0.
Example of input file sample output file

Home.in
2 2 1
1 3 0 1 2
1 3 1 2-1
Home.out
5

This problem we can see that the days and days are independent, and each state of the transfer is a cross-day, so we can split each day to see, (it is said to be called layered map) every day we have a number of transit stations and land months, so that we can achieve the goal of one-way mapping.
As the answer to this question is monotonous, so with the experience of the magic ball problem, we can find the first maximum flow exceeding the given k by enumerating the number of days and adding a new node to run the maximum flow every day.
How to build a diagram:
1. Link an inf to the Earth from the source point to each day.
2. Link an INF to the meeting point from each day's moon.
3. Link an inf to the corresponding node of the day from each node of the previous day (because people can stay at the relay station for a while).
4. For each spacecraft, obtain its last day position, and then obtain the position of the day, between the two points of a capacity for the ship full number of people flow.
Each time you add a new day and then run to the maximum flow more than K can.
As for the no solution, just jump out when ans reaches a great value.

Hey, never thought ah, as to judge whether can reach, the nest used and check set, and the first time t set to 9999
The array is small and has been tle.

#include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std;
const int inf=1e9+7;
int n,m,k,cnt=1,ans,sum,s,t,h[105],a[105][105],len[105],f[105],d[40005],hd[40005];
queue<int>q; struct Edge {int to,nxt,f;}
V[14005];
    void Addedge (int x,int y,int z) {v[++cnt].to=y,v[cnt].f=z;
v[cnt].nxt=hd[x],hd[x]=cnt; } void addedges (int x,int y,int z) {Addedge (x,y,z), Addedge (y,x,0);} int fnd (int x) {if (f[x]!=x) return
    FND (F[x]);
return f[x];
    BOOL BFs () {memset (d,0,sizeof (d));
    D[s]=1;
    Q.push (s);
        while (!q.empty ()) {int U=q.front ();
        Q.pop (); 
                for (int i=hd[u];i;i=v[i].nxt) if (v[i].f&&!d[v[i].to]) {d[v[i].to]=d[u]+1;
            Q.push (v[i].to);
} return d[t]; int dfs (int u,int lft) {if u==t| |
    lft==0) return LFT;
    int r=lft; for (int i=hd[u];i;i=v[i].nxt) if (V[i].f&&r&&d[v[i].to]==d[u]+1) {int W=dfs (v[i].to,min (R,V[I].F));
            V[i].f-=w,v[i^1].f+=w,r-=w;
        if (!r) return lft;
    } if (r==lft) d[u]=0;
return lft-r;
    int main () {freopen ("home.in", "R", stdin);
    Freopen ("Home.out", "w", stdout);
    scanf ("%d%d%d", &n,&m,&k);
    n+=2;
    s=0,t=9999;
    for (int i=1;i<=m+2;i++) f[i]=i;
        for (int i=1;i<=m;i++) {scanf ("%d%d", &h[i],&len[i]);
            for (int j=0;j<=len[i]-1;j++) {scanf ("%d", &a[i][j]);
            a[i][j]+=2;
        if (j) f[fnd (A[i][j])]=fnd (a[i][j-1));
        } if (FND (1)!=fnd (2)) {printf ("0\n");
    return 0;
        while (1) {addedges (Ans*n+1,t,inf), addedges (S,ans*n+2,inf);
            if (ans!=0) {for (int i=1;i<=n;i++) addedges ((ans-1) *n+i,ans*n+i,inf); For (int i=1;i<=m;i++) addedges ((ans-1) *n+a[i][(ans-1)%len[i]],ans*n+a[i][ans%len[i]],h[i]);
        while (BFS ()) Sum+=dfs (S,inf);
        if (sum>=k) break;
    ++ans;
    printf ("%d\n", ans);
return 0; }

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.