int main () { read_input_file(); int total_flow = max_flow(0,n-1); printf("%d\n", total_flow*2/(n-2)); //printf("%d\n", total_flow); return 0; }
int main() { int T; scanf("%d", &T); while (T--) { scanf("%d %d", &J, &M); src = 0; memset(c, 0, sizeof(c)); int max_d = 0; int work = 0; for (int i = 1; i <= J; i++) { int p, r, d; scanf("%d %d %d", &p, &r, &d); work += p; if (max_d < d) { max_d = d; } c[src][i] = p; for (int j = r; j <= d; j++) { c[i][J+j] = 1; } } sink = J + max_d + 1; for (int i = J+1; i <= J+max_d; i++) { c[i][sink] = M; } int max_val = max_flow(); if (max_val == work) { printf("Boss xnby is happy!\n"); } else { printf("Boss xnby is angry!\n"); } } return 0; }
// Gomory-Hu tree を用いた最大流 O(n) int max_flow(const graph &T, int u, int t, int p = -1, int w = 1e9) { if (u == t) return w; int d = 1e9; for(auto &e: T[u]) if (e.to != p) d = min(d, max_flow(T, e.to, t, u, min(w, e.w))); return d; }
int main(){ int i,c,a,b,w,tests=1; while ( scanf("%d\n",&n) == 1 && n ){ memset(g,0,sizeof(g)); memset(parent,-1,sizeof(parent)); memset(queue,0,sizeof(queue)); s = t = 0; scanf("%d %d %d\n",&s,&t,&c); for (i=0;i<c;++i){ scanf("%d %d %d\n",&a,&b,&w); g[a][b] += w; g[b][a] += w; } int res1 = max_flow(s,t); printf("Network %d\nThe bandwidth is %d.\n\n",tests++, res1); } return 0; }
int main() { for (auto fn : flow_networks) { capacity = fn.capacity; n = capacity.size(); assert(max_flow(fn.source, fn.sink) == fn.maxflow); } }
MaxFlowDinicScaling::MaxFlowDinicScaling(FlowGraph _graph) : MaxFlow(_graph) { max_flow_value = 0; max_edge_value = findMaxEdgeValue(); while (max_edge_value > 0) { FlowGraph cur_graph; cur_graph = createGraph(max_edge_value); MaxFlowDinic max_flow(cur_graph); max_flow_value += max_flow.max_flow_value; max_edge_value = max_edge_value / 2; } }
main() { int n, m, a, b, v, st, ed, x, y; int C = 0; while(scanf("%d", &n) == 1 && n) { scanf("%d %d %d", &st, &ed, &m); for(a = 1; a <= n; a++) for(b = 1; b <= n; b++) Map[a][b] = 0; for(a = 0; a < m; a++) { scanf("%d %d %d", &x, &y, &v); Map[x][y] += v; Map[y][x] += v; } printf("Network %d\n", ++C); printf("The bandwidth is %d.\n\n", max_flow(st, ed, n)); } return 0; }
void path_finding(t_data *d) { t_allpaths allpaths; t_bfs bfs; allpaths.paths = VECT_INI(t_onepath); allpaths.idmin = 0; allpaths.sizemin = d->nbroom; init_bfs(&bfs, d); allpaths.maxflow = max_flow(R_OUT(d->idstart), R_IN(d->idend), &bfs, &allpaths); free_bfs(&bfs); if (allpaths.maxflow == 0) { ft_putendl_fd("ERROR: lem-in: No path from start to end", 2); return ; } ft_printf("\n---- PRINT PATH FETCHED ----\n"); ft_vect_print(&allpaths.paths, print_path); ft_printf("ffaflow: %d\n", allpaths.maxflow); ants_invasion(&allpaths, d); }
int main () { read_input_file(); printf("%d\n",max_flow(0,n-1)); return 0; }
void Solve() { int ans=max_flow(vn1+1,scr1,sink1); printf("%d\n",ans); }
void MainWindow::setupMenuBar() { QMenuBar *menubar = new QMenuBar(dynamic_cast<QWidget*>(this)); QWidget *qwmb = dynamic_cast<QWidget*>(menubar); QMenu *file = new QMenu("File", qwmb); QWidget *qwf = dynamic_cast<QWidget*>(file); QAction *new_proj = new QAction("New model", qwf); QAction *open_proj = new QAction("Open model...", qwf); QAction *save_proj = new QAction("Save model", qwf); QAction *export_graph = new QAction("Export graph to .svg", qwf); QAction *quit = new QAction("Quit", qwf); file->addAction(new_proj); file->addAction(open_proj); file->addAction(save_proj); file->addAction(export_graph); file->addSeparator(); file->addAction(quit); QMenu *edit = new QMenu("Edit", qwmb); QWidget *qedit = dynamic_cast<QWidget*>(edit); QAction *add_node = new QAction("Add node",qedit); QAction *remove_node = new QAction("Remove node",qedit); QAction *add_edge = new QAction("Add edge",qedit); QAction *remove_edge = new QAction("Remove edge",qedit); edit->addAction(add_node); edit->addAction(remove_node); edit->addAction(add_edge); edit->addAction(remove_edge); QMenu *solve = new QMenu("Solve", qwmb); QWidget *qsolve = dynamic_cast<QWidget*>(solve); QAction *min_cost_flow = new QAction("Min cost flow",qsolve); QAction *max_cost_flow = new QAction("Max cost flow",qsolve); QAction *max_flow = new QAction("Max flow",qsolve); QAction *cheapest_tree = new QAction("Cheapest tree", qsolve); QAction *cheapest_path = new QAction("Cheapest path...",qsolve); solve->addAction(min_cost_flow); solve->addAction(max_cost_flow); solve->addAction(max_flow); solve->addAction(cheapest_tree); solve->addAction(cheapest_path); QMenu *help = new QMenu("Help", qwmb); menubar->addMenu(file); menubar->addMenu(edit); menubar->addMenu(solve); menubar->addMenu(help); setMenuBar(menubar); connect(quit, SIGNAL(triggered()), this, SLOT(close())); connect(save_proj, SIGNAL(triggered()), this, SLOT(saveProj())); connect(min_cost_flow, SIGNAL(triggered()), this, SLOT(min_cost_flow())); connect(max_cost_flow, SIGNAL(triggered()), this, SLOT(max_cost_flow())); connect(max_flow,SIGNAL(triggered()), this, SLOT(max_flow())); connect(cheapest_tree, SIGNAL(triggered()), this, SLOT(cheapest_tree())); connect(cheapest_path, SIGNAL(triggered()), this, SLOT(cheapest_path())); return; }
int main () { read_input_file(); printf("%d\n",max_flow(posmin,posmax)); return 0; }
int main() { read(); printf("%u\n", max_flow()); }
void run(){ printf("%d\n",max_flow(vn1+1,scr1,sink1)); }