传送门

脑残题

建图都懒得说了

——代码

 #include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 1000001
#define min(x, y) ((x) < (y) ? (x) : (y)) int n, cnt, s, t;
int a[][], dis[N], pre[N];
int head[N], to[N << ], val[N << ], cost[N << ], next[N << ];
bool vis[N]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline void add(int x, int y, int z, int c)
{
to[cnt] = y;
val[cnt] = z;
cost[cnt] = c;
next[cnt] = head[x];
head[x] = cnt++;
} inline bool spfa()
{
int i, u, v;
std::queue <int> q;
memset(vis, , sizeof(vis));
memset(pre, -, sizeof(pre));
memset(dis, / , sizeof(dis));
q.push(s);
dis[s] = ;
while(!q.empty())
{
u = q.front(), q.pop();
vis[u] = ;
for(i = head[u]; i ^ -; i = next[i])
{
v = to[i];
if(val[i] && dis[v] > dis[u] + cost[i])
{
dis[v] = dis[u] + cost[i];
pre[v] = i;
if(!vis[v])
{
q.push(v);
vis[v] = ;
}
}
}
}
return pre[t] ^ -;
} inline int dinic()
{
int i, d, sum = ;
while(spfa())
{
d = 1e9;
for(i = pre[t]; i ^ -; i = pre[to[i ^ ]]) d = min(d, val[i]);
for(i = pre[t]; i ^ -; i = pre[to[i ^ ]])
{
val[i] -= d;
val[i ^ ] += d;
}
sum += dis[t] * d;
}
return sum;
} int main()
{
int i, j, x;
n = read();
s = , t = n + n + ;
memset(head, -, sizeof(head));
for(i = ; i <= n; i++)
{
add(s, i, , );
add(i, s, , );
add(i + n, t, , );
add(t, i + n, , );
for(j = ; j <= n; j++)
{
a[i][j] = read();
add(i, j + n, , a[i][j]);
add(j + n, i, , -a[i][j]);
}
}
printf("%d\n", dinic());
cnt = ;
memset(head, -, sizeof(head));
for(i = ; i <= n; i++)
{
add(s, i, , );
add(i, s, , );
add(i + n, t, , );
add(t, i + n, , );
for(j = ; j <= n; j++)
{
add(i, j + n, , -a[i][j]);
add(j + n, i, , a[i][j]);
}
}
printf("%d\n", -dinic());
return ;
}

最新文章

  1. css字体家族
  2. BINARY SEARCH in read table statement
  3. iOS - Swift SingleClass 单例类
  4. 网络流(费用流)CodeForces 321B:Ciel and Duel
  5. 验证abc三列数字符合我的小弟要求
  6. JavaScript 运动框架 Step by step
  7. ios开发 oc 的类方法与对象方法
  8. python基础-------模块与包(三)正则表达式
  9. TinyMapper 使用总结
  10. dubbo源码分析1——SPI机制的概要介绍
  11. go import 使用方法记录
  12. git-stash用法小结
  13. Javascript深入理解构造函数和原型对象
  14. 《算法》第五章部分程序 part 7
  15. 关于QT和SQLite以及XML
  16. v-if案例解析(element-ui form-item 结合 v-if 动态生成rule规则\表单元素,表单无法验证问题剖析 )
  17. iOS 中的静态库与动态库,区别、制作和使用
  18. Python爬取猫眼top100排行榜数据【含多线程】
  19. layoutSubviews中判断横竖屏
  20. Linux内核(6) - 模块机制与“Hello World!

热门文章

  1. [Tracking] KCF + KalmanFilter目标跟踪
  2. ios基础学习
  3. Dojo的dojoConfig函数
  4. Codeforces Round 513 (Div.1+Div.2)
  5. Map集合应用 取出一个字符串中字母出现的次数。如:字符串:&quot;abcdekka27qoq&quot;&#160;,输出格式为:a(2)b(1)k(2)...
  6. 代码块(block)的使用
  7. Ubuntux下简单设置vim
  8. Yii2.0学习--目录结构
  9. Java 编辑html模板并生成pdf
  10. 七周成为数据分析师06_MySQL