# UVALive-2531 the K-league (Max Stream + enumeration)

Source: Internet
Author: User

The main topic: There are N teams to play, each team need to hit the same number of games, each game just have a team win, a team defeated, give each team the current number of wins and the number of defeats, as well as the remaining number of each team of matches, to determine all possible champions of the team

How to solve the problem: enumerate each team and let the team win all the next races.
If you build a map, it's simpler, and the source point is connected to each game and the capacity is the number of games.
Each match to match the team, capacity for the number of games
Then each team connects to the meeting point, and the capacity is the total winning field of the enumeration team-the winning field of the team

If full, it means the team can get the championship.

``#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace STD;#define M 1000010#define N 10010#define INF 0x3f3f3f3fstructedge{intU, V, cap, flow, next;} E[M];structdinic{intHead[n], d[n];intTot, sink, source;voidInit () {memset(Head,-1,sizeof(head)); tot =0; }inline voidAddedge (intUintVintCAP) {e[tot].u = u; E[TOT].V = v; E[tot].cap = cap; E[tot].flow =0; E[tot].next = Head[u];        Head[u] = tot++; u = u ^ v; v = u ^ v;        u = u ^ v; e[tot].u = u; E[TOT].V = v; E[tot].cap =0; E[tot].flow =0; E[tot].next = Head[u];    Head[u] = tot++; }inline BOOLBFsints) {intU, v;memset(d,0,sizeof(d)); Queue<int>Q;        Q.push (s); D[s] =1; while(! Q.empty ()) {u = Q.front (); Q.pop ();if(U = = sink)return true; for(inti = Head[u]; ~i; i = e[i].next) {v = e[i].v;if(!d[v] && e[i].cap-e[i].flow >0) {D[v] = D[u] +1;                Q.push (v); }            }        }return false; }intDfsintXintA) {if(x = = Sink | | a = =0)returnAintF, Flow =0; for(inti = head[x]; ~i; i = e[i].next) {intv = e[i].v;if(D[v] = = D[x] +1&& E[i].cap-e[i].flow >0) {f = Dfs (V, min (A, e[i].cap-e[i].flow));                E[i].flow + = f; e[i^1].flow-= f;                Flow + + F; A-= f;if(!a) Break; }        }if(Flow = =0) D[x] =0;returnFlow }intMaxflow (intSourceintSink) {intFlow =0; This->sink = sink; while(BFS (source)) Flow + = DFS (source, INF);returnFlow }};D inic dinic;#define MAXNintNintWIN[MAXN], FIGHT[MAXN][MAXN], all, Max;voidInit () {scanf("%d", &n); all =0; Max =-inf;intT for(inti =1; I <= N; i++) {scanf("%d%d", &win[i], &t); max = max (max, win[i]);if(i = =1) All + = Win[i] + t; } for(inti =1; I <= N; i++) for(intj =1; J <= N; J + +) {scanf("%d", &fight[i][j]);if(i = =1) All + = Fight[i][j]; }}voidSolve () {BOOLFlag =false;intTotal, Source =0, sink = N-1, CNT; for(inti =1; I <= N; i++) {total = Win[i]; for(intj =1; J <= N; J + +) Total + = Fight[i][j];if(Total < Max)Continue; CNT = n +1; Dinic.init ();intSum =0; for(intj =1; J <= N; J + +) {if(J! = i) dinic. Addedge (J, Sink, Total-win[j]); for(intK = j +1; K <= N; k++) {if(j = = I | | k = = i)Continue; Dinic.                Addedge (source, CNT, fight[j][k]);                Sum + = Fight[j][k]; Dinic.                Addedge (CNT, J, Fight[j][k]); Dinic.            Addedge (cnt++, K, fight[j][k]); }        }intMaxflow = Dinic. Maxflow (source, sink);if(Maxflow = = Sum) {if(flag)printf(" "); Flag =true;printf("%d", i); }    }printf("\ n");}intMain () {intTestscanf("%d", &test); while(test--)        {init ();    Solve (); }return 0;}``

UVALive-2531 the K-league (Max Stream + enumeration)

Related Keywords:

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.