177 条题解
-
-1
#include<bits/stdc++.h> using namespace std; #define set(x) Set(x) #define REP(i,j,k) for (int i=(j),end=(k);i<=end;++i) #define DREP(i,j,k) for (int i=(j),start=(k);i>=start;--i) #define mp make_pair #define x first #define y second #define pb push_back template<typename T> inline bool chkmin(T &a,const T &b){ return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a,const T &b){ return a < b ? a = b, 1 : 0; } typedef long long LL; typedef pair<int,int> node; const int dmax = 1010, oo = 0x3f3f3f3f; int n, m; int a[dmax][dmax] , ans; int d[dmax], e[dmax]; priority_queue <node> q; inline bool operator >(node a,node b){ return a.y>b.y; } bool p[dmax]; void Set(int x){ p[x] = 1; } void unset(int x){ p[x] = 0; } bool check(int x){ return x != 1 && x != n && !p[x] && e[x] > 0; } void preflow(){ e[1] = oo; d[1] = n - 1; q.push(mp(1, n - 1)); set(1); while (!q.empty()) { bool flag = 1; int k = q.top().x; q.pop(), unset(k); DREP(i, n, 1) if ((d[k] == d[i] + 1 || k == 1) && a[k][i] > 0){ flag = 0; int t = min(a[k][i], e[k]); e[k] -= t; a[k][i] -= t; e[i] += t; a[i][k] += t; if (check(i)) { q.push(mp(i, d[i])); set(i); } if (e[k] == 0) break; } if (flag) { d[k] = oo; REP(i, 1, n) if (a[k][i] > 0) chkmin(d[k], d[i] + 1); } if (check(k)) { q.push(mp(k, d[k])); set(k); } } ans = e[n]; } int main() { n = 2, m = 2; int x, y; scanf("%d%d", &x, &y); a[1][2] += x + y; preflow(); printf("%d\n", ans); return 0; } //#include <bits/stdc++.h> //using namespace std; //struct Plus //{ // int a,b;//定义一个结构体 //}; //stack<int> sta;//定义一个栈 //int main() //{ // Plus c;//结构体变量 // cin >> c.a >> c.b; // sta.push(c.a);//入栈 // sta.push(c.b); // int s; // s += sta.top();//输出栈顶元素 // sta.pop();//出栈 // s += sta.top(); // cout << s;//输出总和 // return 0; //} //#include <bits/stdc++.h> //using namespace std; //int n = 2, a[5], s; //int dfs(int x, int sum) { // if (x > n) return sum; // int i = dfs(x + 1, sum); // int j = dfs(x + 1, sum + a[x]); // if (i == s) return i; // if (j == s) return j; // return -1; //} //int main() { // for (int i = 1;i <= n; i++) scanf("%d", &a[i]), s += a[i]; // cout << dfs(1, 0) << endl; // return 0; //} //#include <bits/stdc++.h> //using namespace std; //int d[5][5], n = 3; //int main() { // int a, b; scanf("%d%d", &a, &b); // memset(d, 0x3f, sizeof d); // d[1][2] = a; d[2][3] = b; // for (int k = 1;k <= n; k++) // for (int i = 1;i <= n; i++) // for (int j = 1;j <= n; j++) // d[i][j] = min(d[i][j], d[i][k] + d[k][j]); // printf("%d\n", d[1][3]); // return 0; //} //#include <iostream> //#include <cstring> //#include <algorithm> //#include <numeric> //#include<iterator> //using namespace std; //int main() //{ // istream_iterator<int> in(cin), eof; // cout << accumulate(in, eof ,0) << endl; // return 0; //} //#pragma GCC diagnostic error "-std=c++11" //#pragma GCC target("avx") //#pragma GCC optimize(1) //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize("Ofast") //#pragma GCC optimize("inline") //#pragma GCC optimize("-fgcse") //#pragma GCC optimize("-fgcse-lm") //#pragma GCC optimize("-fipa-sra") //#pragma GCC optimize("-ftree-pre") //#pragma GCC optimize("-ftree-vrp") //#pragma GCC optimize("-fpeephole2") //#pragma GCC optimize("-ffast-math") //#pragma GCC optimize("-fsched-spec") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-falign-jumps") //#pragma GCC optimize("-falign-loops") //#pragma GCC optimize("-falign-labels") //#pragma GCC optimize("-fdevirtualize") //#pragma GCC optimize("-fcaller-saves") //#pragma GCC optimize("-fcrossjumping") //#pragma GCC optimize("-fthread-jumps") //#pragma GCC optimize("-funroll-loops") //#pragma GCC optimize("-fwhole-program") //#pragma GCC optimize("-freorder-blocks") //#pragma GCC optimize("-fschedule-insns") //#pragma GCC optimize("inline-functions") //#pragma GCC optimize("-ftree-tail-merge") //#pragma GCC optimize("-fschedule-insns2") //#pragma GCC optimize("-fstrict-aliasing") //#pragma GCC optimize("-fstrict-overflow") //#pragma GCC optimize("-falign-functions") //#pragma GCC optimize("-fcse-skip-blocks") //#pragma GCC optimize("-fcse-follow-jumps") //#pragma GCC optimize("-fsched-interblock") //#pragma GCC optimize("-fpartial-inlining") //#pragma GCC optimize("no-stack-protector") //#pragma GCC optimize("-freorder-functions") //#pragma GCC optimize("-findirect-inlining") //#pragma GCC optimize("-fhoist-adjacent-loads") //#pragma GCC optimize("-frerun-cse-after-loop") //#pragma GCC optimize("inline-small-functions") //#pragma GCC optimize("-finline-small-functions") //#pragma GCC optimize("-ftree-switch-conversion") //#pragma GCC optimize("-foptimize-sibling-calls") //#pragma GCC optimize("-fexpensive-optimizations") //#pragma GCC optimize("-funsafe-loop-optimizations") ///#pragma GCC optimize("inline-functions-called-once") //#pragma GCC optimize("-fdelete-null-pointer-checks") //#include <bits/stdc++.h> //using namespace std; //int main() { // int a, b; scanf("%d%d", &a, &b); // printf("%d", a + b); // return 0; //}
信息
- ID
- 1
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 6
- 标签
- 递交数
- 21681
- 已通过
- 7188
- 上传者