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

WHY WA?

Posted by cycpp at 2009-08-04 13:26:28 on Problem 3159
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define INF (1<<30)
#define  N  30005
int dis[N];
struct node
{
    int v,w;
	node(){}
	node(int vv,int ww){v=vv;w=ww;}
	bool operator<(const node & o)const
	{
		return dis[v]>dis[o.v];
	}
};
struct e
{
	int v,w,next;

}E[150005];

int fount;
int head[N];
int rear[N];
void dijkstra(int s,int t,int n)
{
	priority_queue <node> Q;
    int v,w,ite;
	node te;
	fill(dis,dis+n+1,INF);
	dis[1]=0;
	Q.push(node(1,0));
	while(!Q.empty())
	{
		te=Q.top();
		Q.pop();
		if(dis[te.v]!=te.w)continue;
		if(te.v==n||te.w==INF)return;
		for(ite=head[te.v];ite!=-1;ite=E[ite].next)
		{
			v=E[ite].v;
			w=E[ite].w;
			if(dis[te.v]+w<dis[v])
			{
				dis[v]=dis[te.v]+w;
				Q.push(node(v,dis[v]));
			}
		}
	}
}
int main()
{
    int s,t,w,n,m;
    cin>>n>>m;
	fount=0;
	memset(head,-1,sizeof(head));
    for(fount=0;fount<m;++fount)
    {
        scanf("%d%d%d",&s,&t,&w);
		E[fount].v=t;
		E[fount].w=w;
		E[fount].next=-1;
		if(head[s]==-1)
			head[s]=fount;
		else
			E[ rear[s] ].next=fount;
    }
	dijkstra(1,n,n);
    cout<<dis[n]<<endl;
    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