POJ 1724 ROADS
来源:互联网 发布:域名升级访问中sdashao 编辑:程序博客网 时间:2024/06/06 04:27
题目链接
题意:找花费不超过k的最短路。
分析:dijkstra+优先队列+bfs
#include<cstdio>#include<algorithm>#include<vector>#include<iostream>#include<functional>#include<cstring>#include<queue>#define MAX_V 105#define inf 1000000000using namespace std;struct edge{ int to,cost,toll; edge(){} edge(int to,int cost,int toll):to(to),cost(cost),toll(toll){}};struct P{ int first; int second; int third; P(int first,int second,int third):first(first),second(second),third(third){} bool operator<(const P &other)const { return first>other.first; }};int V;vector<edge>G[MAX_V];int k,r;int tol;int dijkstra(int s){ priority_queue<P>que; que.push(P(0,s,0)); while(!que.empty()) { P p=que.top(); que.pop(); int v=p.second; if(v==V) return p.first; for(int i=0;i<G[v].size();i++) { edge e=G[v][i]; if(p.third+e.toll<=k) que.push(P(p.first+e.cost,e.to,p.third+e.toll)); } } return -1;}int main(void){ while(scanf("%d%d%d",&k,&V,&r)==3) { for(int i=0;i<r;i++) { int s,e,l,t; scanf("%d%d%d%d",&s,&e,&l,&t); G[s].push_back(edge(e,l,t));// G[e].push_back(edge(s,l,t)); } tol=0; printf("%d\n",dijkstra(1)); } return 0;}
0 0
- POJ 1724 ROADS
- POJ 1724 ROADS
- poj 1724 ROADS
- Poj 1724 ROADS
- POJ-1724-ROADS
- poj 1724 ROADS
- POJ 1724 ROADS
- POJ-1724-ROADS
- POJ 1724 ROADS (bfs)
- poj 1724 ROADS
- POJ 1724 ROADS
- POJ 1724 ROADS
- POJ 1724 ROADS
- POJ 1724 ROADS
- POJ 1724--ROADS
- poj 1724 ROADS
- poj 1724 ROADS
- POJ-1724 ROADS
- 【Codeforces 703B - Mishka and trip】
- POJ:2585 Window Pains(简单拓扑排序+有难度打map表)
- linux学习第二篇:初识linux简单命令
- Lonlife-ACM 1010 Alarm
- SDUT数据结构实验之串三:KMP应用
- POJ 1724 ROADS
- Linux文件合并去除重复内容
- <hdoj2647>Reward
- Android-通过自定义ViewPager来高仿土巴兔选择装修风格效果(中间放大效果)
- 【mybatis深度历险系列】深入浅出mybatis中原始dao的开发和mapper代理开发
- 关于云服务器搭建的一些心得
- 一个HTTP请求的详细过程
- Log4j 配置
- centos7优化内核参数详解