UVA11248 网络流

N - Frequency Hopping
Time Limit:10000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status Practice UVA 11248
Appoint description:

Description

Download as PDF

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 (0C (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(01<101), b2(02<101) and fp(0 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


太粗心了,在check函数里把j写成了i导致一直wa。。。

题意:给你一些边和容量限制,问是否存在从1到N大小为C的流,不存在的话能否通过增加某一条边的容量来实现。

思路:先求一次最大流,如果最大流大于等于C,显然可行,否则枚举满流的边(最小割),给这些边增加容量。看能否使流量增加到C。增广的时候在先前的最大流的基础上增广。否则会tle。。。



#include  
#include  
#include  
#include  
#include  
using namespace std;  
typedef long long LL;
const LL INF = 1LL << 51;
const int MAXN=150;
int n,E,s,t;
LL C;  
int cur[MAXN],d[MAXN],vis[MAXN];  
struct Edge  
{  
    int from,to;
    LL cap,flow;
    bool operator < (const Edge &A)const{
    	return fromedges,ans,tmpe;  
std::vectorG[MAXN];  
void init(int n){
	for(int i=0;iq;  
    q.push(s);  
    memset(d,-1,sizeof d);
    vis[s]=1;  
    d[s]=0;  
    while(!q.empty()){  
        int u=q.front();q.pop();  
        for(int i=0;ie.flow){  
                q.push(e.to);  
                vis[e.to]=1;  
                d[e.to]=d[u]+1;  
            }  
        }  
    }  
    return vis[t];  
}  
LL dfs(int x,LL a,int t){  
    if(x==t||a==0)return a;  
    LL flow=0,f=0;  
    for(int &i=cur[x];i0){  
            e.flow+=f;  
            edges[G[x][i]^1].flow-=f;  
            flow+=f;  
            a-=f;  
            if(a==0)break;  
        }  
    }  
    return flow;  
}  
LL dinic(int s,int t,LL c){  
    LL flow=0;
    while(bfs(s,t)){
        memset(cur,0,sizeof cur);
        flow+=dfs(s,INF,t);
        if(flow>=c)return flow;
    }
    return flow;  
}  
void get_cut(int s,int t,vector& v){
	v.clear();
	int sz=edges.size();
	for(int i=0;icut;
	get_cut(s,t,cut);
	int sz=edges.size();
	tmpe.clear();
	for(int i=0;i=c){
			ans.push_back(e);
		}
		edges.clear();
		for(int j=0;j=C){
        	puts("possible");
        	continue;
        }
        int m=check(s,t,C-an);
        if(!m)puts("not possible");
        else{
        	sort(ans.begin(), ans.end());
        	printf("possible option:(%d,%d)", ans[0].from+1, ans[0].to+1);
        	for(int i=1;i

你可能感兴趣的:(网络流)