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

哪位大牛帮忙看下,为何一直wa啊!!

Posted by wocha at 2012-08-24 12:52:50 on Problem 1724
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#define M 10120
#define inf 0x3f3f3f3f
using namespace std;
queue<pair<int ,int > > Q;
int max1;
int e,end[M],head[M],next[M],cost[M],length[M];
inline void Init(){
	e=0;
	memset(head,-1,sizeof(head));
} 
inline void add(int u,int v,int l,int w){
	end[e]=v;
	cost[e]=w;
	length[e]=l;
	next[e]=head[u];
	head[u]=e++;
}
int dis[101][M],vis[101][M],cnt[101][M];
void spfa(int n){
    memset(dis,inf,sizeof(dis));
	memset(vis,0,sizeof(vis));
	while(!Q.empty()) Q.pop();
	dis[1][0]=0;
	vis[1][0]=1;
	Q.push(make_pair(1,0));
	while(!Q.empty()){
		int u=Q.front().first;
		int mo=Q.front().second;
		Q.pop();   vis[u][mo]=0;
		for(int i=head[u];i!=-1;i=next[i]){
	        int v=end[i],w=cost[i],le=length[i];
		if(dis[v][mo+w]>le+dis[u][mo]){
	        dis[v][mo+w]=le+dis[u][mo];
		if(!vis[v][mo+w]){
  		vis[v][mo+w]=1;
  		Q.push(make_pair(v,mo+w));
  				}	
			}
		}
	
	}
}
int main(){          
    int n,m;    
    cin>>max1>>n>>m;
	Init();
	int u,v,w,l;
    while(m--){
	scanf("%d%d%d%d",&u,&v,&l,&w);
	add(u,v,l,w);   	
    } 
	spfa(n); 
	int p=inf;
	int t;
	for(int i=0;i<=max1;i++){
	if(p>dis[n][i])
	 p=dis[n][i];
	}  
	if(p==inf) printf("-1\n");
    else        printf("%d\n",p); 
 
	}

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