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

to admin

Posted by LiWang112358 at 2009-11-14 00:27:36 on Problem 1511
管理员同志:
	你好!
	下面是1511 ac的代码,但是却过不去我自己的数据,请问是否要加数据?
	我的数据:
1
4 8
1 2 1
2 1 4
4 1 3
2 4 7
2 3 2
3 2 2
3 4 4
1 3 5

正确答案是24 我的代码25

#include <stdio.h>
#include <stdlib.h>
int const MX=int(1e9),L=1000001;
struct point
{
    int t,l,last;
} edge[2][L];
bool flag[2][L];
int n,e;
__int64 ans;
int q[L],d[L],head[2][L];
void spfa(int num)
{
    int open,closed,i,k;
    open=closed=1;
    q[1]=1;
    for (i=1;i<=n;i++) d[i]=MX;
    d[1]=0;
    while (1)
    {
        k=head[num][q[open]];
        while (k!=-1)
        {
            if (d[edge[num][k].t]>d[q[open]]+edge[num][k].l)
            {
                d[edge[num][k].t]=d[q[open]]+edge[num][k].l;
                if (!flag[num][edge[num][k].t])
                {
                    flag[num][edge[num][k].t]=1;
                    q[++closed]=edge[num][k].t;
                }
            }
            k=edge[num][k].last;
        }
        open++;
        if (open>closed) break;
    }
    for (i=1;i<=n;i++) ans+=d[i];
}
void begin()
{
    int i,j;
    for (i=1;i<=n;i++) 
        for (j=0;j<=1;j++)
        {
                head[j][i]=-1;
                flag[j][i]=0;
        }    
}
int main()
{
    int cases,i,g,f,t,l;
    scanf("%d",&cases);
    for (g=1;g<=cases;g++)
    {
        scanf("%d %d",&n,&e);
        begin();
        for (i=1;i<=e;i++)
        {
            scanf("%d %d %d",&f,&t,&l);
            
            edge[0][i].last=head[0][f];
            edge[0][i].t=t;
            edge[0][i].l=l;
            head[0][f]=i;
            
            edge[1][i].last=head[1][t];
            edge[1][i].t=f;
            edge[1][i].l=l;
            head[1][t]=i;
            
        }
        ans=0;
        spfa(0);
        spfa(1);
        printf("%I64d\n",ans);
    }   
    //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