这个数据真是卡的难受
一开始用kuangbin大大的板子
然后无向图正向反向都搞一个边和一个反边然后T掉了
看了看别人板子之后才发现原来无向图建边原来直接把反向边流量设置为和正边一样的流量就可以了
/* #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 1e5 + 10; const int INF = 0x3f3f3f3f; int cas = 1, T; int d[maxn], cur[maxn], start, tend; struct node { int to, cap, next; //node(){} //node(int a,int b,int c):to(a),cap(b),rev(c){} }edge[maxn << 1]; //vectormp[maxn]; int head[maxn]; bool vis[maxn]; int cnt; void addedge(int start, int to, int cap) { edge[cnt].to = to; edge[cnt].cap = cap; edge[cnt].next = head[start]; head[start] = cnt++; } bool BFS() { //memset(vis,false,sizeof(vis)); memset(d, -1, sizeof(d)); int Q[maxn * 2]; int Thead, Ttail; Thead = Ttail = 0; Q[Ttail++] = start;; d[start] = 0; //vis[start]=1; while (Thead0)//没有标记,且可行流大于0 { //vis[temp.to]=true; d[temp] = d[x] + 1; Q[Ttail++] = temp; } } Thead++; } return false;//汇点是否成功标号,也就是说是否找到增广路 } int DFS(int x, int cap) { if (x == tend)return cap; //vis[start]=true; int flow = 0, f; for (int i = head[x]; i != -1; i = edge[i].next) { int temp = edge[i].to; //if(temp.cap<=0||vis[temp.to])continue; if (d[temp] == d[x] + 1 && edge[i].cap) { f = DFS(temp, min(cap - flow, edge[i].cap)); edge[i].cap -= f; edge[i ^ 1].cap += f; flow += f; if (flow == cap)break; } } if (!flow)d[x] = -2;//防止重搜 return flow; } int maxflow() { int flow = 0, f; while (BFS()) { //memset(vis,false,sizeof(vis)); while ((f = DFS(start, INF))>0) flow += f; } return flow; } int main() { int n, m; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); cnt = 0; memset(head, -1, sizeof(head)); int x, y, u, v, w; //for(int i=0;i= tmax)tend = i, tmax = x; } while (m--) { scanf("%d%d%d", &u, &v, &w); addedge(u, v, w); //addedge(v,u,0); addedge(v, u, w); //addedge(u,v,0); } int ans = maxflow(); printf("%d\n", ans); } } */ /* 最大流模板 dinic算法 */ #include #include #include #include using namespace std; const int INF=0x3f3f3f3f; const int MAXN=1e5+10;//点数的最大值 const int MAXM=2*MAXN+100;//边数的最大值 struct Node { int from,to,next; int cap; }edge[MAXM]; int tol; int dep[MAXN];//dep为点的层次 int head[MAXN]; int n; void init() { tol=0; memset(head,-1,sizeof(head)); } void addedge(int u,int v,int w)//第一条变下标必须为偶数 { edge[tol].from=u; edge[tol].to=v; edge[tol].cap=w; edge[tol].next=head[u]; head[u]=tol++; edge[tol].from=v; edge[tol].to=u; edge[tol].cap=w; edge[tol].next=head[v]; head[v]=tol++; } int BFS(int start,int ends) { int que[MAXN]; int fronts,rear; fronts=rear=0; memset(dep,-1,sizeof(dep)); que[rear++]=start; dep[start]=0; while(fronts!=rear) { int u=que[fronts++]; if(fronts==MAXN)fronts=0; for(int i=head[u];i!=-1;i=edge[i].next) { int v=edge[i].to; if(edge[i].cap>0&&dep[v]==-1) { dep[v]=dep[u]+1; que[rear++]=v; if(rear>=MAXN)rear=0; if(v==ends)return 1; } } } return 0; } int dinic(int start,int ends) { int res=0; int top; int stacks[MAXN];//stack为栈,存储当前增广路 int cur[MAXN];//存储当前点的后继 while(BFS(start,ends)) { memcpy(cur,head,sizeof(head)); int u=start; top=0; while(1) { if(u==ends) { int mins=INF; int loc; for(int i=0;iedge[stacks[i]].cap) { mins=edge[stacks[i]].cap; loc=i; } for(int i=0;i>t; while(t--) { init(); start = 0; scanf("%d%d",&n,&m); int minn = INF; int maxs = -INF; for(int i =1;i<=n;++i){ int x,y; scanf("%d%d",&x,&y); if(xmaxs){ maxs = x; start = i; } } //cout<