Ultraviolet A 11248-Frequency Hopping maximum flow minimum cut entry question cut set Template

Source: Internet
Author: User

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 sendingC secret message fragments from our head quarters (base station 1) toNth base station. germans have developed zämmhäim-a machine which jams the frequency channel between base stations after a station has sent a messa Ge 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 st Ation 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 directly toColonel Al Pacheno. you have to maintain EV El 3 secrecy and destroy all rights 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, E andC whereN (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 m Essage 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 <5001) which represent the number of frequency channels available currently fromb1 tob2. 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 sendC 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 Input4 4 5 1 2 5 1 3 5 2 4 4 4 4 4 4 5 1 1 1 1 3 5 2 4 5 3 4 4 4 4 5 1 1 1 1 3 1 2 4 1 3 4 4 1 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 http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & category = 24 & problem = 2205 & mosmsg = Submission + stored ed + with + ID + 12258596 Liu lujia new book-Training Guide: given a directed network, each side has a capacity. Ask if there is a stream with a traffic of C from 1 to N. If it does not exist, can you modify the capacity of an arc to make the stream exist? Analysis: calculate the maximum flow first. If the traffic is at least C, the possible is output directly. Otherwise, the arc to be modified must be the arc in the smallest cut. Increase the arc capacity to C, and then find the maximum flow to check whether the maximum flow is at least C. Unfortunately, the program written in this way will time out and two important optimizations need to be added. The first optimization is to keep the traffic after finding the maximum stream, and then increase the traffic based on it each time. The second optimization is that it is not necessary to find the maximum stream each time, when the traffic is increased to at least C, it stops.

# Include <iostream> # include <string> # include <algorithm> # include <cstdlib> # include <cstdio> # include <set> # include <map> # include <vector> # include <cstring> # include <stack> # include <cmath> # include <queue> using namespace std; # define CL (x, v); memset (x, v, sizeof (x); # define INF 0x3f3f3f3f # define LL long # define MAXN 5000 struct Edge {int from, to, cap, flow ;}; struct Dinic {int n, m, s, t; vector <Edge> Edges; vector <int> G [MAXN]; // adjacent table, G [I] [j] indicates the number of the j edge of node I in the e array bool vis [MAXN]; int d [MAXN]; int cur [MAXN]; void init (int n) {this-> n = n; for (int I = 0; I <= n; I ++) G [I]. clear (); edges. clear ();} void AddEdge (int from, int to, int cap) {Edge e; e. from = from; e. to = to; e. cap = cap; e. flow = 0; edges. push_back (e); e. from = from; e. to = to; e. cap = 0; e. flow = 0; edges. push_back (e); m = edges. size (); G [from]. push_back (m-2); G [to]. pu Sh_back m-1);} bool BFS () {CL (vis, 0); queue <int> Q; Q. push (s); d [s] = 0; vis [s] = 1; while (! Q. empty () {int x = Q. front (); Q. pop (); for (int I = 0; I <G [x]. size (); I ++) {Edge & e = edges [G [x] [I]; if (! Vis [e. to] & e. cap> e. flow) {vis [e. to] = 1; d [e. to] = d [x] + 1; Q. push (e. to) ;}}} return vis [t];} int DFS (int x, int a) {if (x = t | a = 0) return; int flow = 0, f; for (int & I = cur [x]; I <G [x]. size (); I ++) {Edge & e = edges [G [x] [I]; if (d [x] + 1 = d [e. to] & (f = DFS (e. to, min (a, e. cap-e.flow)> 0) {e. flow + = f; edges [G [x] [I] ^ 1]. flow-= f; flow + = f; a-= f; if (a = 0) break;} return flow;} int Maxflow (int s, int t, int need) {//) // calculate the maximum If the stream is greater than need, exit this-> s = s; this-> t = t; int flow = 0; while (BFS () {CL (cur, 0 ); flow + = DFS (s, INF); if (flow> need) return flow;} // note the return type vector <int> Mincut () {// minimum cut set can be used only after the maximum stream is obtained. BFS (); vector <int> ans; for (int I = 0; I <edges. size (); I ++) {Edge & e = edges [I]; if (vis [e. from] &! Vis [e. to] & e. cap> 0) ans. push_back (I);} return ans;} void Reduce () {// calculate the remaining capacity for (int I = 0; I <edges. size (); I ++) edges [I]. cap-= edges [I]. flow;} void ClearFlow () {// clear the current flow to 0 for (int I = 0; I <edges. size (); I ++) edges [I]. flow = 0 ;}}; bool cmp (const Edge & a, const Edge & B) {return. from <B. from | (. from = B. from &. to <B. to);} Dinic solver; // you must use g ++ to submit c ++ compilation errors. Do not forget to call init (des) int mai. N () {int N, E, C, cas = 0; while (~ Scanf ("% d", & N, & E, & C) {if (! N) break; solver. init (N); int a, B, c; while (E --) {scanf ("% d", & a, & B, & c ); solver. addEdge (a, B, c);} int flow = solver. maxflow (1, N, INF); printf ("Case % d:", ++ cas); if (flow> C) printf ("possible \ n "); else {vector <int> cut = solver. mincut (); solver. reduce (); vector <Edge> ans; for (int I = 0; I <cut. size (); I ++) {Edge & e = solver. edges [cut [I]; int temp = e. cap; e. cap = C; solver. clearFlow (); if (flow + solver. maxflow (1, N, C-flow)> = C) ans. push_back (e); e. cap = temp;} if (ans. empty () printf ("not possible \ n"); else {sort (ans. begin (), ans. end (), cmp); printf ("possible option :( % d, % d)", ans [0]. from, ans [0]. to); for (int I = 1; I <ans. size (); I ++) printf (", (% d, % d)", ans [I]. from, ans [I]. to); printf ("\ n") ;}} 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.