#include<bits/stdc++.h> usingnamespacestd; #define ll long long constint maxn = 405; constint INF=1e9+7;
structEdge { int from, to, cap, flow, cost; Edge(int u,int v,int c,int f, int w):from(u), to(v), cap(c), flow(f), cost(w) {} };
structMCMF { int n, m; vector<Edge> edges; // 边数的两倍 vector<int> G[maxn]; // 邻接表,G[i][j]表示节点i的第j条边在e数组的序号 int inq[maxn]; // 是否在队列中 int d[maxn]; // Bellman-Ford int a[maxn]; // 当起点到i的可改流量 int p[maxn]; // 最短路树上p的入弧编号(path路径)
voidAddedge(int from, int to, int cap,int cost) { edges.push_back(Edge(from, to, cap, 0, cost)); edges.push_back(Edge(to, from, 0, 0, -cost)); m = edges.size(); G[from].push_back(m-2); G[to].push_back(m-1); }