正式开始从2021年12.04年南京站结束
由于本人知识点学习较乱使得在比赛中不能熟练运用为了提高这种能力进行一个bzoj经典题的刷与练习
1.1001 最小割转换为最短路最小
使用对偶图将图变成如下 转换为最短路 使得每个路为一个割的子集
#include<iostream>
#include<cstring>
#include<queue>
#include<utility>
#define x first
#define y second
using namespace std;
const int N = 1100 * 1100 * 2,M = N * 4;
typedef pair<int,int> PII;
int head[N],to[M],last[M],w[M],cnt;
void add(int a,int b,int c){
to[++cnt] = b;
last[cnt] = head[a];
w[cnt] = c;
head[a] = cnt;
to[++cnt] = a;
last[cnt] = head[b];
w[cnt] = c;
head[b] = cnt;
}
int S,T;
int a[1100][1100],b[1100][1100],c[1100][1100];
int dist[N],flag[N];
int dij(){
memset(dist,0x3f,sizeof dist);
memset(flag,0,sizeof flag);
priority_queue<PII,vector<PII>,greater<PII> > q;
q.push({
0,S});
dist[S] = 0;
while(q.size()){
PII p = q.top();
q.pop();
if(flag[p.y]) continue;
flag[p.y] = 1;
for(int i = head[p.y]; i != -1; i = last[i]){
int j = to[i];
if(dist[j] > dist[p.y] + w[i]){
dist[j] = dist[p.y] + w[i];
q.push({
dist[j],j});
}
}
}
return dist[T];
}
int main(){
int n,m;
cin >> n >> m;
int tot = 0,cnt = 1;
memset(head,-1,sizeof head);
for(int i = 1; i <= n; i++){
for(int j = 1; j < m; j++){
scanf("%d",&a[i][j]);
}
}
for(int i = 1; i <= n - 1; i++){
for(int j = 1; j <= m; j++){
scanf("%d",&b[i][j]);
}
}
for(int i = 1; i <= n - 1; i++){
for(int j = 1; j <= m - 1; j++){
scanf("%d",&c[i][j]);
}
}
S = 0,T = n * m * 2 + 1;
for(int i = 1; i <= (n - 1); i++){
for(int j = 1; j <= (m - 1); j++){
++tot;
if(i == 1) add(S,tot,a[i][j]);
if(j == m - 1) add(S,tot,b[i][j + 1]);
if(j == 1) add(tot + n * m,T,b[i][j]);
if(i == n - 1) add(tot + n * m,T,a[i + 1][j]);
add(tot,tot + n * m,c[i][j]);
if(j != m - 1){
add(tot,tot + 1 + n * m,b[i][j + 1]);
}
if(i != n - 1){
add(tot + n * m,tot + m - 1,a[i + 1][j]);
}
}
}
int d = dij();
if(d == 0x3f3f3f3f){
cout << 1 << endl;
}else cout << d << endl;
return 0;
}