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

有大佬帮忙看看我代码吗?感觉好像是这样的

Posted by qq2567722641 at 2019-08-17 11:38:19 on Problem 1062
#include<iostream>
#include<queue> 
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1e3+10;
int head[maxn];
int dis[maxn];
int n,m,cnt,p,l,x;

typedef struct{
	int to,w,gra,NXT;
}edge;
edge e[maxn];

struct node{
	int id,dis;
	node(int id,int dis):id(id),dis(dis){}
	bool operator <(const node &a)const{
		return dis>a.dis;
	}
};

void add(int from,int gra,int to,int w){
	e[++cnt].to=to;
	e[cnt].gra=gra;
	e[cnt].w=w;
	e[cnt].NXT=head[from];
	head[from]=cnt;
}
void dijkstra(int s){
	priority_queue<node>st;
	memset(dis,88,sizeof(dis));
	dis[s]=0;
	st.push(node(s,0));
	while(!st.empty()){
		node f=st.top();st.pop();
		int u=f.id;int d=f.dis;
		if(d!=dis[u])continue;
		for(int i=head[u];i;i=e[i].NXT){
			if((dis[e[i].to]>d+e[i].w)&&abs(e[u].gra-e[e[i].to].gra)<=m){//判断等级
				dis[e[i].to]=d+e[i].w;
				st.push(node(e[i].to,dis[e[i].to]));
			}
		}
	}
	dis[n]+=e[cnt].w;
	cout<<dis[n]<<endl;
}
int main(){
	cnt=0;
	int t,v;
	scanf("%d%d",&m,&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&p,&l,&x);
		add(i,l,i,p);
		for(int j=1;j<=x;j++){
			cin>>t>>v;
			add(i,l,t,v);
		}
	}
	dijkstra(1); 
} 

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