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 ...
随机推荐
- PYTHON调用C接口(基于Ctypes)实现stein算法最大公约数的计算
相关环境配置 mingw,选择相应的32位.64位的版本,主要用于编译动态链接库dll文件,可用vs替代,这里我选择轻量级的mingw windows64位地址:https://sourceforge ...
- PAT 乙级 1081. 检查密码 (15) 【字符串】
题目链接 https://www.patest.cn/contests/pat-b-practise/1081 思路 有一个坑点 可能会输入空格 也就是说 要用 geline 或者 gets() 然后 ...
- could not read symbols: Archive has no index;
could not read symbols: Archive has no index; run ranlib to add one collect2: ld returned 1 exit sta ...
- HDU 1201 Fibonacci Again
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- python_opencv库的学习
一.以灰度图的形式加载彩色图像. https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_ ...
- python- python内置模块 面向对象
1.configparser模块 configparser用于处理特定格式的文件,其本质上是利用open来操作文件 # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2 ...
- Linux_学习_01_常用命令大全
一.文件目录 1.列出目录 ls -a #显示隐藏文件 -l #显示文件和目录的详细资料 -h -lrt tree #显示文件和目录由根目录开始的树形结构 lstree #显示文件和目录由根目录开始的 ...
- 作业3rd
第三周作业 课本学习 使用nmap扫描特定靶机 使用nessus扫描特定靶机 靶机网络情况如下 在攻击机使用Nessus,步骤如下 新建一个扫描 填入目的主机ip,点击开始进行扫描 等待 扫描结果如下 ...
- MongoDB 分片的原理、搭建、应用 !
MongoDB 分片的原理.搭建.应用 一.概念: 分片(sharding)是指将数据库拆分,将其分散在不同的机器上的过程.将数据分散到不同的机器上,不需要功能强大的服务器就可以存储更多的数据和处 ...
- BZOJ3110:[ZJOI2013]K大数查询
浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...