| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求大牛帮我看下3159的代码``不知道哪里错了····#include <iostream>
#include <algorithm>
using namespace std;
struct f
{
int A, B, C;
}temp[2][150001];
bool cmp(f a, f b)
{
return a.A < b.A;
}
int main()
{
int n, m, a, b, c, i = 0, j = 0, k, x, kid[2][30001] = {0};
cin>>n>>m;
while (m--)
{
cin>>a>>b>>c;
if (a < b)
{
temp[0][i].A = a;
temp[0][i].B = b;
temp[0][i].C = c;
i++;
}
else
{
temp[1][j].A = b;
temp[1][j].B = a;
temp[1][j].C = c;
j++;
}
}
sort(temp[0], temp[0]+i, cmp);
sort(temp[1], temp[1]+i, cmp);
for (k=0; k<i; k++)
{
x = kid[0][temp[0][k].A] + temp[0][k].C;
if (x < kid[0][temp[0][k].B] || 0 == kid[0][temp[0][k].B])
kid[0][temp[0][k].B] = x;
}
for (k=0; k<j; k++)
{
x = kid[1][temp[1][k].A] + temp[1][k].C;
if (x < kid[1][temp[1][k].B] || 0 == kid[1][temp[1][k].B])
kid[1][temp[1][k].B] = x;
}
cout<<max(kid[0][n], kid[1][n])<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator