Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大牛们,刚学不久的高二菜鸟刚过这道题,希望大家教教SLF,LLL怎么实现,(附代码)

Posted by ziyuanliu at 2011-03-22 21:16:33 on Problem 3159
#include<iostream>
#include<cstdio>
using namespace std;
int queue[30010];
int road[150010][3];
long long value[30010];
bool q[30010];
int pre[150010]={0};
int last[30010]={0};
int n,m;
int t;
void spfa(int s)
    {int j,l=1,x,i;
    queue[l]=s;
    q[s]=true;
    while(l)
        {x=queue[l];
        l=l-1;
        j=last[x];
        while(j!=0)
            {
                if(value[road[j][1]]>value[x]+road[j][2])
                    {value[road[j][1]]=value[x]+road[j][2];
                    if(!q[road[j][1]])
                        {l=l+1;
                        queue[l]=road[j][1];
                        q[road[j][1]]=true;
                        }
                    }
                j=pre[j];
            }
            q[x]=false;
        }
    return;}
int main()
{
    
    int a,b,c;
    scanf("%d",&n);
    scanf("%d",&m);
    for(int i=1;i<=n;i++)
        {value[i]=2147483647;
        q[i]=false;}
    for(int i=1;i<=m;i++)
        {scanf("%d",&a);
        scanf("%d",&b);
        scanf("%d",&c);
        road[i][0]=a;
        road[i][1]=b;
        road[i][2]=c;
        pre[i]=last[a];
        last[a]=i;}
        value[1]=0;
    /*for(int i=m+1;i<=n+m;i++)
        {road[i][0]=0;
            road[i][1]=i-m;
        road[i][2]=0;}*/ 
    spfa(1);
    printf("%d\n",value[n]-value[1]);
    //system("PAUSE");
    return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator