比赛 |
20120720 |
评测结果 |
AAWWAWWWWW |
题目名称 |
阻击补给线 |
最终得分 |
30 |
用户昵称 |
Truth.Cirno |
运行时间 |
0.228 s |
代码语言 |
C++ |
内存使用 |
1.72 MiB |
提交时间 |
2012-07-20 08:44:43 |
显示代码纯文本
#include <cstdio>
using namespace std;
const int MAXINT=1000000000;
int ava=0,ptow[501],way[124751],wayright[124751],waynext[124751];
void addway(int x,int y,int right)
{
int pos;
pos=ptow[x];
if (pos==-1)
{
ptow[x]=ava;
way[ava]=y;
waynext[ava]=-1;
wayright[ava++]=right;
}
else
{
while (waynext[pos]!=-1)
pos=waynext[pos];
way[ava]=y;
waynext[pos]=ava;
waynext[ava]=-1;
wayright[ava++]=right;
}
}
int cal(int pos)
{
int right=0;
pos=ptow[pos];
while (pos!=-1)
{
right+=wayright[pos];
pos=waynext[pos];
}
return(right);
}
int main(void)
{
freopen("t2bb.in","r",stdin);
freopen("t2bb.out","w",stdout);
int i,n,m,x,y,right,temp,minright=MAXINT;
scanf("%d%d",&n,&m);
for (i=0;i<n;i++)
ptow[i]=-1;
for (i=0;i<m;i++)
{
scanf("%d%d%d",&x,&y,&right);
addway(x,y,right);
addway(y,x,right);
}
for (i=0;i<n;i++)
{
temp=cal(i);
if (minright>temp)
minright=temp;
}
printf("%d\n",minright);
return(0);
}