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 AB 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

32-bit signed integer type is capable of doing all arithmetic.

教训

注意样例中先输入的是点数还是边数

调了一上午,写了三遍,队列,栈,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);
}

最新文章

  1. stl循环删除
  2. jar包里查找指定的class文件,排查是否存在或重复,工具软件:Java Class Finder
  3. eclipse下使用maven配置库托管jar包
  4. java相关的路径获取 (转载 http://tomfish88.iteye.com/blog/971255)
  5. 开源CMS建站项目DNN研究与心得
  6. C语言中的宏定义
  7. 二维数组在text,image的应用
  8. 读书笔记——Java IO
  9. 百度cdn资源公共库共享及常用开发接口
  10. Java学习笔记19(String类)
  11. Gradle 笔记——Java构建入门
  12. CSS3_天猫商品墙
  13. CITS1401 Computational Thinking with Python
  14. pip的常用命令
  15. rxjs简单入门
  16. UVA 815 Flooded!
  17. 如何解决PHP的高并发和大流量的问题
  18. ASP.NET Core 中使用 GrayLog 记录日志
  19. Jmeter之目录结构
  20. HNOI2019 摸鱼记

热门文章

  1. dojo 官方翻译 dojo/string 版本1.10
  2. 调用微信接口token的问题
  3. android 电池(一):锂电池基本原理篇【转】
  4. glViewport()函数和glOrtho()函数的理解(转)
  5. JAVA-配置path环境
  6. matlab之sortrows()函数
  7. RQNOJ 429 词链:单调栈
  8. python-常用内置函数与装饰器
  9. app测试点-1
  10. linux命令学习:echo详解,格式化输出,不换行输出