比赛 |
20100421 |
评测结果 |
WWWWAWWA |
题目名称 |
星际争霸 |
最终得分 |
25 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-04-21 11:27:29 |
显示代码纯文本
#include<fstream.h>
#include<cmath>
#include<cstring>
using namespace std;
ifstream fin("starwar.in");
ofstream fout("starwar.out");
int main()
{
static int flow[101][101],limit[101][101];
static bool check[101];
static int last[101];
int n,m,r,i,j,ans,delta,r1,r2,x1,max=1000000000;
int x[100],y[100],z[100];
ans=0;
fin>>n>>m>>r;
r=r*r;
for (i=1;i<=n;i++)
{
fin>>x[i]>>y[i]>>z[i];
}
x[0]=0;
y[0]=0;
z[0]=0;
for (i=1;i<=m;i++)
{
fin>>r1>>r2;
limit[r1+1][r2+1]=(x[r1]-x[r2])*(x[r1]-x[r2])+(y[r1]-y[r2])*(y[r1]-y[r2])+(z[r1]-z[r2])*(z[r1]-z[r2]);
}
int q[100],fa[100],dist[100];
bool bb[100];
memset (q,0,sizeof(q));
memset (bb,false,sizeof(bb));
memset (fa,0,sizeof(fa));
for (i=0;i<n;i++)
dist[i]=max;
int h=0;
int t=1;
q[t]=1;
bb[1]=true;
dist[1]=0;
while (h!=t)
{
h=(h%n)+1;
for (i=1;i<=n+1;i++)
{
if ((limit[q[h]][i]>0) && (dist[q[h]]+limit[q[h]][i]<dist[i]))
{
dist[i]=dist[q[h]]+limit[q[h]][i];
fa[i]=q[h];
if (bb[i]==false)
{
t=(t%n)+1;
q[t]=i;
bb[i]=true;
}
}
}
bb[q[h]]=false;
}
for (i=1;i<=n+1;i++)
if (dist[i]>r)
limit[i][n+2]=max;
for (;;)
{
for (i=1;i<=n+2;i++)
{
last[i]=0;
check[i]=false;
}
last[1]=10000;
do
{
i=0;
do
{
i++;
}while ((i<=n+2) && ((last[i]==0) || (check[i])));
if (i>n+2)
break;
for (j=1;j<=n+2;j++)
if (last[j]==0)
{
if (flow[i][j]<limit[i][j])
last[j]=i;
else
if (flow[j][i]>0)
last[j]=0-i;
}
check[i]=true;
}while (last[n+2]==0);
if (last[n+2]==0)
break;
delta=max;
i=n+2;
do
{
j=i;
i=abs(last[j]);
if (last[j]>0)
x1=limit[i][j]-flow[i][j];
else
x1=flow[j][i];
if (x1<delta)
delta=x1;
}while (i!=1);
i=n+2;
do
{
j=i;
i=abs(last[j]);
if (last[j]>0)
flow[i][j]+=delta;
else
flow[j][i]-=delta;
}while (i!=1);
ans+=delta;
}
fout<<ans<<endl;
fin.close();
fout.close();
return 0;
}