N-frequency hopping
Time limit: 10000 ms
Memory limit: 0 KB
64bit Io format: % LLD & % llusubmit status practice ultraviolet A 11248 appoint description:
Description
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 N Are actively operational through wireless channels. Immediately we require sending C Secret Message fragments from our head quarters (base station 1) 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 particle 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 directlyColonel Al pacheno.You have to maintain level 3 secrecy and destroy all privileges ents 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 numbersN, EAndCWhereN(0 <n <101) represents the number of base stations, E (E <10000) represents the number of available connections between the base stations andC(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)AndFP (0 <FP <1, 5001)Which represent the number of frequency channels available currently fromB1ToB2. 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 sendCSecret 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
It's so careless that J is written as I in the check function that it keeps Wa...
Question: give you some edge and capacity restrictions and ask if there is a stream with the size from 1 to n being C. If not, can you increase the capacity of a certain edge.
Idea: Find the maximum stream first. If the maximum stream is greater than or equal to C, it is feasible. Otherwise, enumerate the full stream edge (minimum cut) and increase the capacity for these sides. Check whether the traffic can be increased to C. In the case of augmented, the original largest stream is scaled up. Otherwise, tle...
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<queue> 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 from<A.from||(from==A.from&&to<A.to); } }; std::vector<Edge>edges,ans,tmpe; std::vector<int>G[MAXN]; void init(int n){for(int i=0;i<n;i++)G[i].clear();edges.clear();tmpe.clear();}void addedge(int u,int v,int w){ edges.push_back((Edge){u,v,w,0}); edges.push_back((Edge){v,u,0,0}); int m=edges.size(); G[u].push_back(m-2); G[v].push_back(m-1); } int bfs(int s,int t) { memset(vis,0,sizeof vis); queue<int>q; 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;i<G[u].size();i++){ Edge &e=edges[G[u][i]]; if(!vis[e.to]&&e.cap>e.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];i<G[x].size();++i){ Edge &e=edges[G[x][i]]; if(d[e.to]==d[x]+1&&(f=dfs(e.to,min(a,e.cap-e.flow),t))>0){ 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<int>& v){v.clear();int sz=edges.size();for(int i=0;i<sz;i+=2){Edge &e=edges[i];if(vis[e.from]&&!vis[e.to]){v.push_back(i);}}}int check(int s,int t,LL c){std::vector<int>cut;get_cut(s,t,cut);int sz=edges.size();tmpe.clear();for(int i=0;i<sz;i++)tmpe.push_back(edges[i]);ans.clear();for(int i=0;i<cut.size();i++){Edge &e=edges[cut[i]];e.cap=e.flow+C;if(dinic(s,t,c)>=c){ans.push_back(e);}edges.clear();for(int j=0;j<sz;++j)edges.push_back(tmpe[j]);}return ans.size();}int main(){ int cas=1; while(scanf("%d%d%lld",&n,&E,&C)!=EOF) { if(n==0&&E==0&&C==0)return 0; init(n); int u,v,w; while(E--) { scanf("%d%d%d",&u,&v,&w); u--,v--; addedge(u,v,w); } printf("Case %d: ", cas++); s=0,t=n-1; LL an=dinic(s,t,C); if(!C||an>=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<m;i++)printf(",(%d,%d)",ans[i].from+1,ans[i].to+1); puts(""); } } return 0;}
Uva11248 network stream