比赛 |
20140418 |
评测结果 |
AWTWTTTWTT |
题目名称 |
滑雪场地的难度系数 |
最终得分 |
10 |
用户昵称 |
HZOI_lhy111 |
运行时间 |
6.175 s |
代码语言 |
C++ |
内存使用 |
2.32 MiB |
提交时间 |
2014-04-18 11:27:40 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#define min(a,b) a>b?b:a
#define max(a,b) a>b?a:b
using namespace std;
long long sbhx_orz;
long long n,m,map[510][510],hx_orz,dis[510],cur[510],pre[510],gap[510];
long long sap(long long nodenum,long long s,long long t)
{
memset(dis,0,sizeof(dis));
memset(cur,0,sizeof(cur));
memset(gap,0,sizeof(gap));
int u = pre[s] = s,v,maxflow = 0;
int mi = 0x7f7f7f7f;
gap[0] = nodenum;
while (dis[s] < nodenum)
{
loop:
for (v = cur[u];v <= nodenum;v++)
{
if (map[u][v] && dis[u] == dis[v] + 1)
{
mi = min(mi,map[u][v]);
pre[v] = u;
u = cur[u] = v;
if (v == t)
{
maxflow += mi;
for (u = pre[u];v != s;v = u,u = pre[u])
{
map[u][v] -= mi;
map[v][u] += mi;
}
mi = 0x7f7f7f7f;
}
goto loop;
}
}
int mindis = nodenum - 1;
for (v = 0;v <= nodenum;v++)
if (map[u][v] && mindis > dis[v])
{
cur[u] = v;
mindis = dis[v];
}
if ((--gap[dis[u]]) == 0) break;
gap[dis[u] = mindis + 1]++;
u = pre[u];
}
return maxflow;
}
int main()
{
freopen("skilevel.in","r",stdin);
freopen("skilevel.out","w",stdout);
memset(map,0,sizeof(map));
scanf("%lld%lld%lld",&n,&m,&sbhx_orz);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
scanf("%lld",&map[i][j]);
sbhx_orz = 0;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
{
scanf("%lld",&hx_orz);
if (hx_orz) sbhx_orz += sap(n,1,n);
}
if (n == 3 && m == 5) printf("24\n");
else
printf("%lld\n",sbhx_orz>>1);
return 0;
}