Hot Pursuit II HRBU
来源:互联网 发布:linux抓包工具 编辑:程序博客网 时间:2024/06/05 04:43
点击打开链接
初次接触次短路 模板题
#include <bits/stdc++.h>using namespace std;#define N 0x3f3f3f3fstruct node1{ int v; int w;};struct node2{ friend bool operator < (node2 n1,node2 n2) { return n1.s>n2.s; } int id; int s; int type;};vector <node1> edge[1010];int dis[1010][2],book[1010][2];int n,m;void calculate();int main(){ node1 cur; int i,j,v,w; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { edge[i].clear(); } for(i=1;i<=n;i++) { scanf("%d",&m); for(j=1;j<=m;j++) { scanf("%d%d",&v,&w); cur.v=v,cur.w=w; edge[i].push_back(cur); } } calculate(); printf("%d\n",dis[n][1]); } return 0;}void calculate(){ priority_queue <node2> que; node1 tem; node2 cur; int i,p,type; memset(dis,0x3f,sizeof(dis)); memset(book,0,sizeof(book)); dis[1][0]=0; cur.id=1,cur.s=0,cur.type=0; que.push(cur); while(!que.empty()) { cur=que.top(); que.pop(); p=cur.id,type=cur.type; if(book[p][type]==1) continue; book[p][type]=1; for(i=0;i<edge[p].size();i++) { tem=edge[p][i]; if(book[tem.v][0]==0&&dis[tem.v][0]>dis[p][type]+tem.w) { dis[tem.v][1]=dis[tem.v][0]; cur.id=tem.v,cur.s=dis[tem.v][1],cur.type=1; que.push(cur); dis[tem.v][0]=dis[p][type]+tem.w; cur.id=tem.v,cur.s=dis[tem.v][0],cur.type=0; que.push(cur); } else if(book[tem.v][1]==0&&dis[tem.v][1]>dis[p][type]+tem.w) { dis[tem.v][1]=dis[p][type]+tem.w; cur.id=tem.v,cur.s=dis[tem.v][1],cur.type=1; que.push(cur); } } } return;}
阅读全文
0 0
- Hot Pursuit II HRBU
- hrbust 1050 Hot Pursuit II【SPFA+次短路】
- HOT
- HOT!!!!
- Hot
- 浅谈Matching Pursuit和Orthogonal Matching Pursuit
- ----单词:pursuit、canonical、两会
- The Pursuit of Happyness
- the pursuit of happiness
- the pursuit of happiness
- our pursuit of happiness
- Orthogonal matching pursuit
- The Pursuit of Happyness
- Projectioni Pursuit Regression
- 《The pursuit of happness》观后感
- 《Pursuit of Happiness》之我见
- 看完《the pursuit of happiness》
- On the Pursuit of Fashion
- Python/C/C++ 万能注释模版
- Python3 内置函数
- 顺序表应用7:最大子段和之分治递归法
- QImage和 Mat 转化
- 如何用UE替换空白行
- Hot Pursuit II HRBU
- JS监听手机的物理返回键(亲测有效)
- 设置-通用-辅助功能-按钮形状后所有按钮会加上下划线,本文的目的是去掉这些下划线
- mySQL之pymysql的使用
- 内建函数式接口
- web中文件下载用创建Iframe处理
- Android 横竖屏切换对Activity生命周期的影响
- 在javascript中==和===的区别
- dtree例子