版本比较
【学习笔记】图论
正文
增加 11 行删除 11 行
26 行未改动27282930313233343548 行未改动84858687888990919271 行未改动16416516616716816917017117243 行未改动21621721821922022122222322478 行未改动3033043053063073083093103116 行未改动318319320321322323324325326133 行未改动全部展开46046146246346446546646746813 行未改动4824834844854864874884894906 行未改动49749849950050150250350450552 行未改动558559560561562563564565566138 行未改动全部展开70570670770870971071171271316 行未改动26 行未改动int h[N], e[M * 2], ne[M * 2], f[M * 2], idx;int n, m, S, T;void add(int a, int b, int c) {e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}int d[N], cur[N];bool bfs() {For(i, 0, n + 1) d[i] = -1, cur[i] = -1;48 行未改动cin >> a >> b >> c;add(a, b, c);}cout << dinic() << '\n';return 0;}```:::71 行未改动}int flow = 0, cost = 0;EK(flow, cost);cout << flow << ' ' << cost;return 0;}```:::43 行未改动bool dijkstra() {For(i, 1, n) vis[i] = 0, dist[i] = INF, incf[i] = 0;priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;q.push(mp(0, S));incf[S] = INF;dist[S] = 0;while (q.size()) {auto t = q.top();q.pop();78 行未改动int h[N], e[M * 2], ne[M * 2], f[M * 2], l[M * 2], idx;void add(int a, int b, int c, int d) {e[idx] = b, f[idx] = d - c, l[idx] = c, ne[idx] = h[a], h[a] = idx++;e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}bool bfs() {For(i, 0, n + 1) d[i] = -1;queue<int> q;q.push(S);6 行未改动if (d[j] == -1 && f[i]) {d[j] = d[t] + 1;cur[j] = h[j];if (j == T) return 1;q.push(j);}}}return 0;133 行未改动全部展开if (dinic() != tot) cout << "No Solution";else {int res = f[idx - 1];f[idx - 1] = f[idx - 2] = 0;S = s, T = t;res += dinic();cout << res << '\n';}return 0;13 行未改动using namespace std;#define x first#define y second#define mp(Tx, Ty) make_pair(Tx, Ty)#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)#define debug(...) fprintf(stderr, __VA_ARGS__)#define range(Tx) begin(Tx),end(Tx)const int N = 5e4 + 10, M = 125000 + 10 + N + 10, INF = 2147483647;6 行未改动e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}int cur[N], d[N];bool bfs() {For(i, 0, n + 1) d[i] = -1;queue<int> q;q.push(S);d[S] = 0, cur[S] = h[S];while (q.size()) {52 行未改动else {int res = f[idx - 1];f[idx - 1] = f[idx - 2] = 0;S = t, T = s;cout << res - dinic();}return 0;}```138 行未改动全部展开考虑对于一个集合 $S$,我们建出一个图:$$\begin{array}{ccccccc}S & \longrightarrow & N \\& \nearrow & \\L - S & \longrightarrow & R - N\end{array}$$16 行未改动26 行未改动27282930313233343548 行未改动84858687888990919271 行未改动16416516616716816917017117243 行未改动21621721821922022122222322478 行未改动3033043053063073083093103116 行未改动318319320321322323324325326133 行未改动全部展开46046146246346446546646746813 行未改动4824834844854864874884894906 行未改动49749849950050150250350450552 行未改动558559560561562563564565566138 行未改动全部展开70570670770870971071171271316 行未改动26 行未改动int h[N], e[M * 2], ne[M * 2], f[M * 2], idx;int n, m, S, T;void add(int a, int b, int c) {e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}int d[N], cur[N];bool bfs() {For(i, 0, n + 1) d[i] = -1, cur[i] = -1;48 行未改动cin >> a >> b >> c;add(a, b, c);}cout << dinic() << '\n';return 0;}```:::71 行未改动}int flow = 0, cost = 0;EK(flow, cost);cout << flow << ' ' << cost;return 0;}```:::43 行未改动bool dijkstra() {For(i, 1, n) vis[i] = 0, dist[i] = INF, incf[i] = 0;priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;q.push(mp(0, S));incf[S] = INF;dist[S] = 0;while (q.size()) {auto t = q.top();q.pop();78 行未改动int h[N], e[M * 2], ne[M * 2], f[M * 2], l[M * 2], idx;void add(int a, int b, int c, int d) {e[idx] = b, f[idx] = d - c, l[idx] = c, ne[idx] = h[a], h[a] = idx++;e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}bool bfs() {For(i, 0, n + 1) d[i] = -1;queue<int> q;q.push(S);6 行未改动if (d[j] == -1 && f[i]) {d[j] = d[t] + 1;cur[j] = h[j];if (j == T) return 1;q.push(j);}}}return 0;133 行未改动全部展开if (dinic() != tot) cout << "No Solution";else {int res = f[idx - 1];f[idx - 1] = f[idx - 2] = 0;S = s, T = t;res += dinic();cout << res << '\n';}return 0;13 行未改动using namespace std;#define x first#define y second#define mp(Tx, Ty) make_pair(Tx, Ty)#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)#define debug(...) fprintf(stderr, __VA_ARGS__)#define range(Tx) begin(Tx),end(Tx)const int N = 5e4 + 10, M = 125000 + 10 + N + 10, INF = 2147483647;6 行未改动e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;}int cur[N], d[N];bool bfs() {For(i, 0, n + 1) d[i] = -1;queue<int> q;q.push(S);d[S] = 0, cur[S] = h[S];while (q.size()) {52 行未改动else {int res = f[idx - 1];f[idx - 1] = f[idx - 2] = 0;S = t, T = s;cout << res - dinic();}return 0;}```138 行未改动全部展开考虑对于一个集合 $S$,我们建出一个图:$$\begin{array}{ccccccc}S & \longrightarrow & N \\& \nearrow & \\L - S & \longrightarrow & R - N\end{array}$$16 行未改动