#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. 进程退出:SIGINT、SIGTERM和SIGKILL区别

    一.SIGINT.SIGTERM和SIGKILL区别 SIGINT与SIGTERM区别1)SIGINT关联ctrl+c2)SIGINT只能结束前台进程3)通过ctrl+c对当前进程发送结束信号,信号被 ...

  2. Vue脚手架菜鸟级错误 npm run dev

    ERROR Failed to compile with 1 errors Failed to resolve loader: stylus-loaderYou may need to install ...

  3. Kubernetes k8s 基于Docker For Windows

      开启和安装Kubernetes k8s 基于Docker For Windows   0.最近发现,Docker For Windows Stable在Enable Kubernetes这个问题上 ...

  4. Maven手动导本地jar到项目

    第一步:先把目标jar安装在本地,下面是安装到本地的步骤:在cmd命令中,输入:mvn install:install-file -Dfile=C:\Users\Ter\Desktop\jqd_doc ...

  5. MYSQL:查询单表中不同邮箱最近一次发送状态

    1.联系方式表-customer_contact: id email 1 123456@qq.com 2 987643@qq.com 3 hahaha@qq.com 2.发送邮件记录表-contact ...

  6. SQL Server表水平分区

    随着项目的运行时间越来越久,数据库的数据会越来越多,某些表因为数据量的变大查询起来会很慢,而且拥有大量数据的表整张表的数据都存于一个mdf文件中,不利于数据文件的维护和管理,我们一般都会通过优化sql ...

  7. DRF框架(六)——三大认证组件之认证组件、权限组件

    drf认证组件 用户信息表 from django.db import models from django.contrib.auth.models import AbstractUser class ...

  8. 2019-7-18 collections,time,random,os,sys,序列化模块(json和pickle)应用

    一.collections模块 1.具名元组:namedtuple(生成可以使用名字来访问元素的tuple) 表示坐标点x为1  y为2的坐标 注意:第二个参数可以传可迭代对象,也可以传字符串,但是字 ...

  9. Linux查看CPU信息计算CPU核数量

    1. 物理CPU的个数: cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l 2. 每个物理CPU的核心数量: ...

  10. UOJ399 CTSC2018 假面 期望、DP

    传送门 \(Q \leq 200000 , C \leq 1000 , m_i \leq 100\)-- 先考虑如何维护最后一次操作时所有人的血量期望.不难发现我们需要的复杂度是\(O(Qm_i)\) ...