zoukankan      html  css  js  c++  java
  • uva 11248 最大流 ISAP


    E

    Frequency Hopping

    Input: Standard Input

    Output: Standard Output

     

     

     

    20th July, 1942

    Colonel Al Pacheno,

          According to the previous order “ref: 232/UK44i/334sda#nh$X3y”, you are required back in the DOI (Department of intelligence, London) to head the special programming contingent immediately. You are to assign a programmer for the job whose specification is attached with this letter.

          Level 3 Secrecy must be maintained.

     

    Sincerely,

    General Shaan Konary

    Director, DOI

    London

    Ps: Sorry to ruin your Caribbean holiday

     

    232/UK44i/334sda#nh$X3y/Appx-301a

    At this moment, through out Europe, our base station numbers 1 to N are actively operational through wireless channels. Immediately we require sending C secret message fragments from our head quarters (base station 1) to Nth base station. Germans have developed Zämmhäim – a machine which jams the frequency channel between base stations after a station has sent a message fragment. In that case, the base stations must transmit using a different frequency channel for each message fragment. There are several unidirectional channels set up between base stations at this moment. We can only make arrangements to set up number of frequency channels only between two base stations. Your task is to check whether all the message fragments can be sent to the desired base station with or without increasing frequency channel between any two particular base stations. You have to give us all possible options if it is required to increase frequency channel between two stations.

    --End of Attachment

    As members of Secret Programmers Group (SPG) you are assigned to solve this problem within 5 hrs and deliver the solution directly to Colonel Al Pacheno. You have to maintain Level 3 secrecy and destroy all documents corresponding to this as soon as you deliver the solution.

    Input:

    There will be multiple test cases. The first line of each test case contains three numbers N, E and C where N (0<N<101) represents the number of base stations, E (E<10000) represents the number of available connections between the base stations and C (C<2000000000) represents the number of secret message fragments that are required to send from station 1 to station N. After that, there will be E lines. Each line contains 3 numbers: b1(0<b1<101), b2(0<b2<101) and fp (0<fp<5001) which represent the number of frequency channels available currently from b1 to b2. Input is terminated when N=E=C=0.

    Output:

    For each test case, there will be one line of output. First, you have to print the case number. If it is possible to send C secret message fragments from the current status the output will be “possible”. Otherwise, you have to print all pairs of stations (in ascending order) if it is possible send the required message fragments by increasing the frequency channel between any one of them. If it is still impossible, you have to print “not possible”.

    Sample Input                            Output for Sample Input

    4 4 5

    1 2 5

    1 3 5

    2 4 5

    3 4 5

    4 4 5

    1 2 1

    1 3 5

    2 4 5

    3 4 1

    4 4 5

    1 2 1

    1 3 1

    2 4 1

    3 4 1

    0 0 0

     

    Case 1: possible

    Case 2: possible option:(1,2),(3,4)

    Case 3: not possible

     


    Problemsetter: Syed Monowar Hossain

    Special Thanks: Abdullah al Mahmud

    最大流, 求最小割,然后枚举最小割中弧,改其容量为C,看是否能使得最大流达到C,并输出可能的方案,抄白书:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<vector>
    #include<cstdlib>
    #include<algorithm>
    #include<queue>
    
    using namespace std;
    
    #define LL long long
    #define ULL unsigned long long
    #define UINT unsigned int
    #define MAX_INT 0x7fffffff
    #define MAX_LL 0x7fffffffffffffff
    #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
    #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
    #define INF 2000000000
    #define MAXN 111
    #define MAXM 22222
    
    struct edge{
        int u, v, cap, flow, nxt;
    }e[MAXM];
    int h[MAXN], cc;
    
    void add(int u, int v, int cap, int flow){
        e[cc]=(edge){u, v, cap, flow, h[u]};
        h[u]=cc++;
    }
    
    void reduce(){ for(int i=0; i<cc; i++) e[i].cap-=e[i].flow; }
    
    bool vis[MAXN];
    
    bool operator <(const edge &x, const edge &y){
        return x.u<y.u || (x.u==y.u&&x.v<y.v);
    }
    
    int d[MAXN], s, t, cur[MAXN];
    
    void bfs(){
        queue<int> q;
    
    //    cout<<t<<endl;
        memset(vis, 0, sizeof(vis));    vis[t]=true;
        d[t]=0;     q.push(t);
        while(!q.empty()){
            int u=q.front();    q.pop();
    //      cout<<u<<endl;
    
            for(int i=h[u]; i!=-1; i=e[i].nxt){
    //            i^=1;
                int cap=e[i^1].cap, v=e[i^1].u, flow=e[i^1].flow;
                if(!vis[v] && cap>flow){
                    vis[v]=true;
                    q.push(v);
                    d[v]=d[u]+1;
                }
    //            i^=1;
            }
        }
    }
    
    vector<int> Mincut(){
        bfs();
        vector<int> ans;
        for(int i=0; i<cc; i++){
            int u=e[i].u, v=e[i].v, cap=e[i].cap;
            if(!vis[u] && vis[v] && cap>0) ans.push_back(i);
        }
        return ans;
    }
    
    int num[MAXN], p[MAXN], n;
    int Augment(){
        int u=t, a=INF;
        while(u!=s){
            a=MIN(a, e[p[u]].cap-e[p[u]].flow);
            u=e[p[u]].u;
    //        cout<<"a"<<endl;
        }
        for(u=t; u!=s; u=e[p[u]].u){
            e[p[u]].flow+=a;
            e[p[u]^1].flow-=a;
    //        cout<<"b"<<endl;
        }
        return a;
    }
    
    int isap(int need){
        bfs();
        memset(num, 0, sizeof(num));
        int i;
        for(i=0; i<n; i++) num[d[i]]++;
        for(i=0; i<n; i++) cur[i]=h[i];
        int flow=0;
        for(int u=s; d[s]<n;){
            if(u==t){
                flow+=Augment();
                if(flow>=need) return flow;
                u=s;
            }
            bool ok=false;
            for(i=cur[u]; i!=-1; i=e[i].nxt){
                int v=e[i].v, cap=e[i].cap, flow=e[i].flow;
                if(d[u] == d[v]+1 && cap>flow){
                    ok=true;
                    p[v]=i;
                    cur[u]=i;
                    u=v;
                    break;
                }
            }
            if(!ok){
                int tmp=n-1;
                for(int i=h[u]; i!=-1; i=e[i].nxt) if(e[i].cap>e[i].flow)
                    tmp=MIN(tmp, d[e[i].v]);
                if(--num[d[u]]==0) break;
                num[d[u]=tmp+1]++;
                cur[u]=h[u];
                if(u!=s) u=e[p[u]].u;
            }
    //        cout<<"adf"<<endl;
        }
        return flow;
    }
    
    void clearFlow(){
        for(int i=0; i<cc; i++) e[i].flow=0;
    }
    
    int main(){
    //    freopen("C:\Users\Administrator\Desktop\in.txt","r",stdin);
        int ee, c, T=1;
        while(scanf(" %d %d %d", &n, &ee, &c)==3 && n){
            int i, u, v, cap;
            memset(h, -1, sizeof(h));       cc=0;
            for(i=0; i<ee; i++){
                scanf(" %d %d %d", &u, &v, &cap);           u--;        v--;
                add(u, v, cap, 0);      add(v, u, 0, 0);
            }
            s=0;            t=n-1;
    
            printf("Case %d: ", T++);
            int flow=isap(INF);
            if(flow>=c){
                printf("possible
    ");   continue;
            }
            vector<int> mincut=Mincut();
            vector<edge> ans;
            reduce();
            for(int i=0; i<mincut.size(); i++){
                int &cap=e[mincut[i]].cap;
                cap=c;
                clearFlow();
                if(flow+isap(c-flow)>=c) ans.push_back(e[mincut[i]]);
                cap=0;
            }
            if(ans.empty()){
                printf("not possible
    ");   continue;
            }
            sort(ans.begin(), ans.end());
            printf("possible option:(%d,%d)", ans[0].u+1, ans[0].v+1);
            for(i=1; i<ans.size(); i++) printf(",(%d,%d)", ans[i].u+1, ans[i].v+1);
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    JQuery0007:JQuery跨域无刷新分页
    H5_0034:toast提示
    H5_0032:chrome以窗口模式运行(无地址栏与标签栏)
    H5_0031:浏览器弹窗
    JN_0022:VSCode操作技巧 去除空行 去掉换行付
    JQuery0003:事件触发与解除
    CSS0001: CSS判断手机 平板 PC
    Web_0006:阿里云服务器OSS缓存设置清理
    H5_0030:iframe 全屏嵌入,父级获取iframe中嵌入的dom对象
    JN_0020:Chrome保存整个网页为图片
  • 原文地址:https://www.cnblogs.com/ramanujan/p/3329487.html
Copyright © 2011-2022 走看看