POJ 1724 ROADS 最短路 邻接表 + bfs +优先队列
来源:互联网 发布:backtrack5软件下载 编辑:程序博客网 时间:2024/05/17 23:26
最近比较懒,一种方法A了以后不想再去学习别的方法,诶,需要调整
本题:邻接表 + bfs +优先队列 32MS还行
View Code
#include<stdio.h>#include<string.h>#include<queue>using namespace std;#define INF 100000000#define maxn 103#define maxm 10003struct node{ int c, l, w; node(int cc,int ll,int ww):c(cc),l(ll),w(ww) {} friend bool operator<(node a,node b) { return a.l > b.l; }};int tot,n,m,ww;int head[maxn],dis[maxn];struct edge{ int v,next,w,l;}list[maxm];void add(int s,int t, int l, int w){ list[tot].v = t; list[tot].l = l; list[tot].w = w; list[tot].next = head[s]; head[s]= tot++;}void init(){ int i; for(i=0;i<=n;i++) dis[i]=INF; memset(head,-1,sizeof(head)); tot =0;}void bfs(){ priority_queue<node>q; int i,j; q.push(node(1,0,0)); while(!q.empty()) { node u = q.top();q.pop(); if(u.c == n) { printf("%d\n",u.l);return; } for(i=head[u.c];i!=-1;i=list[i].next) { node p = u; p.w += list[i].w; p.l += list[i].l; p.c = list[i].v; if(p.w <= ww) q.push(p); } } printf("%d\n",-1);}int main(){ int a, b, c, d; while(~scanf("%d%d%d",&ww,&n,&m)) { init(); while(m--) { scanf("%d%d%d%d",&a,&b,&c,&d); add(a,b,c,d); } bfs(); } return 0;}
- POJ 1724 ROADS 最短路 邻接表 + bfs +优先队列
- Poj 1724 ROADS (搜索 最短路 BFS优先队列)
- POJ 1724ROADS(费用最短路:优先队列+BFS)
- POJ-1724-ROADS(优先队列,邻接表,BFS)
- 【poj 1724】 ROADS 最短路(dijkstra+优先队列)
- poj 1724 ROADS 邻接表+优先队列+spfa()
- POJ1724---ROADS (最短路变形(邻接表+优先队列))
- 最短路-邻接表(优先队列)写
- POJ 1724 ROADS (优先队列+BFS)
- POJ 1724 ROADS(BFS + 优先队列)
- POJ 1724 ROADS(bfs最短路)
- HDU 2544 最短路 静态邻接表+优先队列 dijkstra
- hdu 2544 最短路(Dijkstra 邻接表+优先队列)
- POJ 1724 ROADS(领接链表的BFS+优先队列)
- POJ ROADS DFS BFS 优先队列 入门
- POJ 1724 ROADS 有约束的最短路问题, BFS
- POJ 1724 ROADS 最短路
- Poj 1251 Jungle Roads (邻接表 + 优先队列 + Prime 最小生成树)
- POJ 2263 Heavy Cargo 最短路dijkstra
- POJ 3013 Big Christmas Tree SPFA模版
- 对指针运算符*文字说明的一点点理解
- 欧拉回路入门学习
- POJ 2513 Colored Sticks 并查集 + 字典树 + 欧拉回路
- POJ 1724 ROADS 最短路 邻接表 + bfs +优先队列
- hdu 4027 Can you answer these queries?
- POJ 1149 PIGS 最大流
- POJ 2112 Optimal Milking 二分+floyd+最大流
- POJ 1459 Power Network 最大流水题
- POJ 1087 A Plug for UNIX 最大流
- POJ 2559 Largest Rectangle in a Histogram DP
- POJ 2537 Tight words DP
- ssh action中service无法注入,报空指针问题