博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3159 差分约束
阅读量:6948 次
发布时间:2019-06-27

本文共 1009 字,大约阅读时间需要 3 分钟。

思路:

很普通很普通的一道差分约束。。 就是Dijkstra的时候要进行堆优化

// by SiriusRen#include 
#include
#define N 150050using namespace std;int n,m,xx,yy,zz,tot=1;int first[30050],next[N],w[N],v[N],dis[30050];bool vis[30050];struct node{
int at,weight;}jy,temp;priority_queue
pq;bool operator <(node a,node b){
return a.weight>b.weight;}void add(int x,int y,int z){ w[tot]=z;v[tot]=y; next[tot]=first[x];first[x]=tot++;}void Dijkstra(){ jy.at=1;jy.weight=0; pq.push(jy); while(!pq.empty()){ jy=pq.top(),pq.pop(); if(vis[jy.at])continue; vis[jy.at]=1;dis[jy.at]=jy.weight; for(int i=first[jy.at];i;i=next[i]){ if(vis[v[i]])continue; temp.at=v[i],temp.weight=jy.weight+w[i]; pq.push(temp); } }}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++)scanf("%d%d%d",&xx,&yy,&zz),add(xx,yy,zz); Dijkstra(); printf("%d\n",dis[n]);}

这里写图片描述

转载于:https://www.cnblogs.com/SiriusRen/p/6532375.html

你可能感兴趣的文章
【LeetCode 100_二叉树_遍历】Same Tree
查看>>
数学论文生成器的论文……被接受了
查看>>
电机随笔
查看>>
05机器学习实战之Logistic 回归scikit-learn实现
查看>>
安装PIL 点滴 fatal error: 'freetype/fterrors.h' file not found
查看>>
递归,尾递归,回溯
查看>>
POJ-1488(字符串应用)
查看>>
浅探SpringMVC中HandlerExecutionChain之handler、interceptor
查看>>
读大话设计模式有感
查看>>
获取当前WEB应用全路径
查看>>
网络编程的演进——从Apache到Nginx
查看>>
mui 中template 的使用
查看>>
2018.11.04-3988-地理课(geography)
查看>>
linux命令总结
查看>>
[激励机制]浅谈内部竞争——如何让你的员工玩命干活?
查看>>
把一个控制器的view添加到另外一个控制器
查看>>
pc端和移动端下拉刷新
查看>>
Maven详解之聚合与继承
查看>>
Spark(二)CentOS7.5之Spark2.3.1HA安装
查看>>
内存池和tcmalloc的性能比较
查看>>