#include <bits/stdc++.h>
using namespace std; const int maxn = 5e4 + ;
const int inf = 0x3f3f3f3f;
int n, head[maxn], dis[maxn], cnt;
struct node{
int to, w, next;
} ed[maxn*]; //数组开2*maxn超时,开大一点
inline void add( int u, int v, int w ){
ed[cnt].to = v;
ed[cnt].w = w;
ed[cnt].next = head[u];
head[u] = cnt++;
} inline int max( int a, int b ){
return a>b ? a:b;
} inline int min( int a, int b ){
return a<b ? a:b;
} inline void spfa( int beg ){
bool vis[maxn];
memset( vis, , sizeof(vis) );
memset( dis, -inf, sizeof(dis) );
queue<int> q;
q.push(beg);
dis[beg] = ;
vis[beg] = ;
while( !q.empty() ){
int u = q.front();
q.pop();
vis[u] = ;
for( int i=head[u]; i!=-; i=ed[i].next ){
int v = ed[i].to;
if( dis[v] < dis[u]+ed[i].w ){
dis[v] = dis[u]+ed[i].w;
if( !vis[v] ){
vis[v] = ;
q.push(v);
}
}
}
}
} int main(){
while( ~scanf("%d", &n) ){
cnt = ;
int a = inf, b = -;
memset( head, -, sizeof(head) );
for( int i=; i<n; i++ ){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
add( u, v+, w );
a = min( a, u );
b = max( b, v+ );
}
for( int i=a; i<=b; i++ ){
add( i-, i, );
add( i, i-, - );
}
spfa(a);
printf("%d\n", dis[b]);
} return ;
}

hdu1384Intervals(差分约束)的更多相关文章

  1. Hdu1384-Intervals(差分约束)

    Problem Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.Wr ...

  2. Candies-POJ3159差分约束

    Time Limit: 1500MS Memory Limit: 131072K Description During the kindergarten days, flymouse was the ...

  3. poj3159 差分约束 spfa

    //Accepted 2692 KB 1282 ms //差分约束 -->最短路 //TLE到死,加了输入挂,手写queue #include <cstdio> #include & ...

  4. ZOJ 2770火烧连营——差分约束

    偶尔做了一下差分约束. 题目大意:给出n个军营,每个军营最多有ci个士兵,且[ai,bi]之间至少有ki个士兵,问最少有多少士兵. ---------------------------------- ...

  5. POJ 2983 Is the Information Reliable? 差分约束

    裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...

  6. 2014 Super Training #6 B Launching the Spacecraft --差分约束

    原题:ZOJ 3668 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3668 典型差分约束题. 将sum[0] ~ sum ...

  7. POJ 1364 King --差分约束第一题

    题意:求给定的一组不等式是否有解,不等式要么是:SUM(Xi) (a<=i<=b) > k (1) 要么是 SUM(Xi) (a<=i<=b) < k (2) 分析 ...

  8. [USACO2005][POJ3169]Layout(差分约束)

    题目:http://poj.org/problem?id=3169 题意:给你一组不等式了,求满足的最小解 分析: 裸裸的差分约束. 总结一下差分约束: 1.“求最大值”:写成"<=& ...

  9. ShortestPath:Layout(POJ 3169)(差分约束的应用)

                布局 题目大意:有N头牛,编号1-N,按编号排成一排准备吃东西,有些牛的关系比较好,所以希望他们不超过一定的距离,也有一些牛的关系很不好,所以希望彼此之间要满足某个关系,牛可以 ...

随机推荐

  1. 使用poi读取excel数据示例

    使用poi读取excel数据示例 分两种情况: 一种读取指定单元格的值 另一种是读取整行的值 依赖包: <dependency> <groupId>org.apache.poi ...

  2. logback不同业务的日志打印到不同文件

    logback不同业务的日志打印到不同文件    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/mggwct/article/details/777 ...

  3. Spring boot启动成功后输出提示

    添加logback-spring.xml,将log输出到文件,控制台输出的level改为error因此只会出处banner src/main/resources/banner.txt的内容为 star ...

  4. 2017ACM/ICPC广西邀请赛 Color it

    Color it Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Tota ...

  5. Android 横竖屏切换处理

    最近在做一个平板项目,有横竖屏切换的问题,写一下处理的方法. 第一种:禁止横竖屏切换. 对于单独的Activity,使用下面的方式直接配置: <activity android:name=&qu ...

  6. 前端与算法 leetcode 28.实现 strStr()

    # 前端与算法 leetcode 28.实现 strStr() 题目描述 28.移除元素 概要 这道题的意义是实现一个api,不是调api,尽管很多时候api的速度比我们写的快(今天这个我们可以做到和 ...

  7. Ubuntu下好用的pdf工具

    安装okular sudo apt-get install okular 汉化 sudo apt-get install kde-l10n-zhcn 然后打开PDF文件时,右键选择打开方式选择okul ...

  8. repost: Deep Reinforcement Learning

    From: http://wanghaitao8118.blog.163.com/blog/static/13986977220153811210319/ accessed 2016-03-10 深度 ...

  9. SpringBoot+Vue前后端分离项目,maven package自动打包整合

    起因:看过Dubbo管控台的都知道,人家是个前后端分离的项目,可是一条打包命令能让两个项目整合在一起,我早想这样玩玩了. 1. 建立个maven父项目 next 这个作为父工程,next Finish ...

  10. CentOS7-Docker 安装 Gitlab

    官方教程 https://docs.gitlab.com/omnibus/docker/ 搜索镜像 [root@master ~]# docker search gitlab 拉取镜像 [root@m ...