[差分约束]POJ 3159——Candies
来源:互联网 发布:二次视频解析接口源码 编辑:程序博客网 时间:2024/05/20 20:43
题目概述
有
使最大差值最大。
解题思路
不难看出这是一道差分约束的问题。
因为要使最大差值最大,所以先给任意一个值0,其他数给
但是
#include<cstdio>#include<cstring>#include<queue>#define max(x,y) ((x)>(y)?(x):(y))using namespace std;const int maxn=30005,maxm=150005;struct jz{ int id,x; bool operator<(const jz &b)const{return x>b.x;}};priority_queue<jz> heap;inline int _read(){ int num=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9') num=num*10+ch-48,ch=getchar(); return num*f;}int n,m,dis[maxn];int tot,lnk[maxn],son[maxm],w[maxm],nxt[maxm];bool vis[maxn];void add(int x,int y,int z){ nxt[++tot]=lnk[x];lnk[x]=tot;son[tot]=y;w[tot]=z;}int DIJ(){ memset(dis,63,sizeof(dis)); while (!heap.empty()) heap.pop(); heap.push((jz){1,0});dis[1]=0; while(!heap.empty()){ int x=heap.top().id;heap.pop(); while(vis[x]&&!heap.empty()) x=heap.top().id,heap.pop(); if (vis[x]) break; vis[x]=1; for (int j=lnk[x];j;j=nxt[j]) if (!vis[son[j]]&&dis[x]+w[j]<dis[son[j]]) dis[son[j]]=dis[x]+w[j],heap.push((jz){son[j],dis[son[j]]}); } int ans=0;for (int i=1;i<=n;i++) ans=max(ans,dis[i]-dis[1]); return ans;}int main(){ freopen("exam.in","r",stdin); freopen("exam.out","w",stdout); n=_read(),m=_read(); for (int i=1;i<=m;i++){ int x=_read(),y=_read(),z=_read(); add(x,y,z); } return printf("%d\n",DIJ()),0;}
阅读全文
0 0
- [差分约束]POJ 3159——Candies
- POJ 3159 Candies——差分约束
- POJ 3159 Candies(差分约束系统)
- 【POJ 3159】 Candies 差分约束系统
- POJ 3159 Candies 差分约束+spfa
- POJ--3159[Candies] 差分约束
- poj 3159 Candies 差分约束 + spfa
- poj-3159-Candies-差分约束+stack
- POJ 3159 Candies 差分约束系统
- poj 3159 Candies 差分约束
- POJ 3159 Candies 差分约束
- POJ 3159 Candies(差分约束)
- POJ 3159 Candies(差分约束系统)
- poj 3159 Candies(差分约束)
- POJ 3159 Candies(差分约束)
- POJ 3159 Candies 差分约束
- 差分约束系统 & poj 3159 Candies
- poj--3159--Candies(简单差分约束)
- 安装了JDK1.8 但在eclipse-jee-kepler-SR1-win32-x86_64中最高版本只为1.7
- gulp总结
- [bzoj2400]Spoj 839 Optimal Marks 最小割
- 数据库的基础知识
- light oj 1220 Mysterious Bacteria
- [差分约束]POJ 3159——Candies
- docker network
- 70%以上业务由H5开发,手机QQ Hybrid 的架构如何优化演进?
- 文件下载/导出
- ActiveMQ错误:Wire format negotiation timeout: peer did not send his wire format
- navicat 10.1.7 注册码
- sklearn库之各分类算法简单应用
- Python os 和 os.path模块详解
- Toolbar自定义及自定义控件类的三个构造函数解析