Candies
Candies
| Time Limit: 1500MS | Memory Limit: 131072K | |
| Total Submissions: 30247 | Accepted: 8409 |
Description
During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the kids loved candies very much and often compared the numbers of candies they got with others. A kid A could had the idea that though it might be the case that another kid B was better than him in some aspect and therefore had a reason for deserving more candies than he did, he should never get a certain number of candies fewer than B did no matter how many candies he actually got, otherwise he would feel dissatisfied and go to the head-teacher to complain about flymouse’s biased distribution.
snoopy shared class with flymouse at that time. flymouse always compared the number of his candies with that of snoopy’s. He wanted to make the difference between the numbers as large as possible while keeping every kid satisfied. Now he had just got another bag of candies from the head-teacher, what was the largest difference he could make out of it?
Input
The input contains a single test cases. The test cases starts with a line with two integers N and M not exceeding 30 000 and 150 000 respectively. N is the number of kids in the class and the kids were numbered 1 through N. snoopy and flymouse were always numbered 1 and N. Then follow M lines each holding three integers A, B and c in order, meaning that kid A believed that kid B should never get over c candies more than he did.
Output
Output one line with only the largest difference desired. The difference is guaranteed to be finite.
Sample Input
2 2
1 2 5
2 1 4
Sample Output
5
Hint
教训
注意样例中先输入的是点数还是边数
调了一上午,写了三遍,队列,栈,vector,结构体。。。
终于不TLE了,WA了
原来就是因为这个。。。。记住这血的教训
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAXM 150010
#define MAXN 30010
int e_num,head[MAXN],cnt,n,m,dis[MAXN];
int q[MAXN],top;
bool f[MAXN];
struct node
{
int pre,to,v;
}e[MAXM];
int qread()
{
int j=;
char ch=getchar();
while(ch<=''&&ch>=''){j=j*+ch-'';ch=getchar();}
return j;
}
void insert(int from,int to,int v)
{
e[++e_num].to=to;
e[e_num].v=v;
e[e_num].pre=head[from];
head[from]=e_num;
}
void spfa(int s,int t)
{
memset(dis,0x3f,sizeof(dis));
memset(f,,sizeof(f));
int point=s;dis[s]=;
q[++top]=point;
f[point]=;
while(top>)
{
point=q[top];
top--;
f[point]=;
for(int i=head[point];i;i=e[i].pre)
{
int k=e[i].to;
if(dis[point]+e[i].v<dis[k])
{
dis[k]=dis[point]+e[i].v;
if(f[k]==)
{
q[++top]=k;
f[k]=;
}
}
}
}cout<<dis[t];
}
int main()
{
n=qread(),m=qread();
int a,b,c;
for(int i=;i<=m;i++)
{
a=qread(),b=qread(),c=qread();
insert(a,b,c);
}
spfa(,n);
}
Candies的更多相关文章
- 【POJ2886】Who Gets the Most Candies?-线段树+反素数
Time Limit: 5000MS Memory Limit: 131072K Case Time Limit: 2000MS Description N children are sitting ...
- poj 3159 Candies 差分约束
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 22177 Accepted: 5936 Descrip ...
- Who Gets the Most Candies?(线段树 + 反素数 )
Who Gets the Most Candies? Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%I64d &am ...
- poj---(2886)Who Gets the Most Candies?(线段树+数论)
Who Gets the Most Candies? Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 10373 Acc ...
- poj3159 Candies(差分约束,dij+heap)
poj3159 Candies 这题实质为裸的差分约束. 先看最短路模型:若d[v] >= d[u] + w, 则连边u->v,之后就变成了d[v] <= d[u] + w , 即d ...
- HDU 5127 Dogs' Candies
Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...
- C. Om Nom and Candies 巧妙优化枚举,将复杂度控制在10e6
C. Om Nom and Candies 无线超大背包问题 #include <iostream> #include <cstdio> #include <cstrin ...
- POJ 3159 Candies (栈优化spfa)
Candies 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description During the kinderga ...
- POJ 3159 Candies(差分约束,最短路)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 20067 Accepted: 5293 Descrip ...
- (poj)3159 Candies
题目链接:http://poj.org/problem?id=3159 Description During the kindergarten days, flymouse was the monit ...
随机推荐
- CUDA: 共享内存与同步
CUDA C支持共享内存, 将CUDA C关键字__shared__添加到变量声明中,将使这个变量驻留在共享内存中.对在GPU上启动的每个线程块,CUDA C编译器都将创建该变量的一个副本.线程块中的 ...
- Halcon下载、安装
下载地址: 官网:http://www.halcon.com/halcon/download/ Halcon学习网:http://www.ihalcon.com/read.php?tid=56 { 最 ...
- Linux桥接网络配置
在虚拟机网络配置中,选择桥接的方式.然后进入linux进行设置. 编辑 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPR ...
- 数据结构ADT是什么
抽象数据类型的缩写 abstract data type .表示数据结构的抽象模型.数据结构是一个数据概念的定义,通过各种工具对数据结构的概念类型的描述称之为抽象数据类型,简单地说是指一个数学模型以及 ...
- MVC+Ext.net零基础学习记录(一)
由于最近开发一个项目,决定使用MVC+EXT.NET,决定将学习的这个过程记录下来 本人和很多菜鸟一样,之前既没有使用过MVC开发,也没有接触过EXT.NET,所以这将是一个大家共同学习的过程,文章中 ...
- 常见的CSS命名
1:header(头部)logo topbar lang search topmenu banner nav headbox active(活动的) selectselectTop selectLi ...
- Ubuntu apt-get update 失败【转】
本文转载自:http://www.jianshu.com/p/0de2b5717ce8 1 $ sudo apt-get update 报了一堆错误: Err http://cn.archive.ub ...
- iOS数据持久化存储之归档NSKeyedArchiver
归档是一种很常用的文件储存方法,几乎任何类型的对象都能够被归档储存(实际上是一种文件保存的形式),收集了网上的一些资料并结合自己的一些经验,总结如下. 一.使用archiveRootObject进行简 ...
- jQuery 中的常用函数
on() : 方法在被选元素及子元素上添加一个或多个事件处理程序.自1.7 版本起,on()方法是 bind(),live() 和 delegate()方法的替代品 语法: $(selector).o ...
- python爬虫知识点总结(七)PyQuery详解
官方学习文档:http://pyquery.readthedocs.io/en/latest/api.html 一.什么是PyQuery? 答:强大有灵活的网页解析库,模仿jQuery实现.如果你觉得 ...