Candies(差数约分系统-最短路)

Rust供应链攻击深度解析:从构建脚本到过程宏注入的防御实战 软件供应链安全已成为现代软件开发的核心议题,它关注从代码编写到最终部署的整个流程中可能引入的安全风险。其核心原理在于攻击者不再直接攻击目标应用,而是通过污染其依赖、构建工具或分发渠道等上游环节,实现大规模、隐蔽的入侵。这种攻击方式的技术价值在于能够绕过传统的应用层防护,直接植入难以检测的后门。在Rust生态中,这一风险尤为突出,因为其高度依赖中心化的包管理器和强大的元编程能力。具体到应用场景,攻击者可能通过篡改`Cargo.toml`中的依赖、在`build.rs`构建脚本中嵌入恶意逻辑,或利用**过程宏* 阅读详情

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
32-bit signed integer type is capable of doing all arithmetic.

n个小孩分糖吃,给出一些约束条件,a,b,x就是b小孩不能比a小孩多大于x的糖果。这样的情况下,问1,n小孩最多差多少糖果。
设糖果数为d,那么就可以转化为 d[b] - d[a] <= x,再转换一下就是d[b] < d[a] + x,对,就是那个最短路的判断条件……然后这题就神奇的转换成了最短路。
转化成yy思想就是,b这个人最多比a多x个糖果,然后他肯定是这些路中取最小的那个。可以画一组样例理解一下
1 2 8
2 3 10
2 4 2
4 3 3

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
ll head[30005],d[30005],n,m;
int st[30005];
bool leap[30005];
struct Node
{
    ll u,v,w,next;
}node[150005];
void add_edge(ll u,ll v,ll w,ll tot)
{
    node[tot].u = u;node[tot].v = v;
    node[tot].w = w;
    node[tot].next = head[u];
    head[u] = tot;
}
void spfa(ll x)
{
    for(ll i = 1;i <= n;i++)d[i] = inf;
    for(ll i = 1;i <= n;i++)leap[i] = false;
    leap[x] = true;d[x] = 0;
    int tot = 0;
    st[tot++] = x;
    while(tot)
    {
        ll u = st[--tot];
        leap[u] = false;
        for(ll i = head[u];i != -1;i = node[i].next)
        {
            ll e = node[i].v;
            if(d[e] > d[u] + node[i].w)
            {
                d[e] = d[u] + node[i].w;
                if(!leap[e])
                {
                    leap[e] = true;st[tot++] = e;
                }
            }
        }
    }

}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    while(scanf("%d%d",&n,&m) != EOF)
    {
        for(ll i = 1;i <= n;i++)head[i] = -1;
        for(ll i = 1;i <= m;i++)
        {
            ll u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,i);
        }
        ll temp = 1;
        spfa(temp);
        ll ans = abs(d[1] - d[n]);
        printf("%d\n",ans);
    }
    return 0;
}

然后这题还特妹的卡spfa,手动模拟栈才可以过……

相关推荐

实战指南:用Python实现ONVIF WS-Discovery设备发现(附完整代码)

本文提供了一份详细的实战指南,介绍如何使用Python实现基于ONVIF标准的WS-Discovery设备发现协议。文章深入解析了协议原理、网络通信模型,并提供了完整的代码实现,帮助开发者快速构建智能安防和物联网应用中的设备自动发现工具,有效提升网络设备集成与管理的效率。

chair的专栏 1113

K - Candies(用栈 求最短路,邻接表)

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

CHEN_ZAN_YU的博客 298

从零搭建《火影忍者》手游服务端:Linux环境部署与全流程实战

游戏服务器后端开发是构建大型多人在线体验的核心技术,其原理涉及高并发网络通信、分布式系统架构与数据一致性保障。在技术价值上,一套稳定高效的服务端不仅能支撑海量玩家实时交互,更是游戏业务逻辑、经济系统和安全防线的基石。典型的应用场景包括MMORPG、回合制卡牌、SLG等中重度手游。本文以《火影忍者》IP的横版卡牌回合制手游为例,聚焦于**手工服务端**的完整搭建过程,详细拆解从Linux系统初始化、MySQL与**Redis**缓存部署、核心服务编译、到代理后台联调的全链路实践,为开发者深入理解游戏后端架构提

weixin_30800615的博客 336

Poj 3159 Candies(最短路)

题意:班上有n个同学,现在有一些糖要分给他们,设第i个同学得到的糖为p[i],分糖必须满足条件:第i个同学要求第j个同学的糖不能超过自己k个,即p[j] - p[i] = 0。要求在满足这些条件的情况下,求出p[n] - p[1]的最大值。 据说是一道差分约束系统=-=。然后博主去zz的去学了一下什么是差分约束系统。然后博主又不是很明白的回来了,没有办法讲出了什么差分约束系统。所以就放一个博主觉

PK__PK的博客 378

最全中文停用词表(可直接复制)

最全的停用此表整理 词表名 词表文件 中文停用词表 cn_stopwords.txt 哈工大停用词表 hit_stopwords.txt 百度停用词表 baidu_stopwords.txt 机器智能实验室停用词库 scu_stopwords.txt 以上停用词表链接:https://github.com/goto456/stopwords 以下是我常用的1893个停用词,可直接复制 ! " # $ % & ' ( ) * + , - -- . .. ... ....

dilifish的博客 12万+

别再手动盘点了!教你给微信小程序仓库系统加个‘扫码枪’:完整扫码入库与查询功能实现

本文详细介绍了如何为微信小程序仓库系统添加扫码入库与查询功能,实现零硬件成本的智能仓储管理。通过优化摄像头参数、增强动态识别算法和深度整合业务逻辑,提升扫码精度和效率,同时提供混合查询方案应对复杂场景。这套方案显著提升入库效率,降低错误率,适用于各类仓储管理需求。

weixin_30844577的博客 298

POJ3159Candies(差分约束系统)

DescriptionDuring 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 the

Hawkeye_z的博客 720

搭建PX4开发系统(Ubuntu 22.04)

本文是《从零开始学 PX4 无人机开发》系列第二篇,适合开发者在 Ubuntu 系统下快速搭建 PX4 编译与仿真环境,支持 QGroundControl、Gazebo、MAVSDK 等完整工具链。

qq_15856721的博客 4195

POJ3159-Candies-最短路

POJ3159-Candies-最短路 Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 32821 Accepted: 9192 DescriptionDuring the kindergarten days, flymouse was the monitor of his class. Occasio

君安在AreYouWell 797

手把手教你用Cadence Virtuoso设计折叠式共源共栅放大器(0.18μm工艺实战)

本文详细介绍了在0.18μm工艺下使用Cadence Virtuoso设计折叠式共源共栅放大器的完整流程。从工艺参数获取、电路架构分析到具体参数计算和仿真验证,提供了实战设计指南,帮助工程师掌握这一模拟IC设计中的关键技术,特别适合需要中等增益和较大输出摆幅的应用场景。

open4的博客 405

【Zephyr电源与功耗专题】13_PMU电源驱动介绍

本文介绍的PMU芯片包含2路DCDC和6路LDO,在Zephyr实时操作系统下实现了完整的电源管理解决方案。

zero的博客 842

Poj3159 Candies(最短路)

题意: 给出两点的最大差值,求出1到n的最大差值 思路: 其实就是求1-n的最短路 #include <cstdio> #include <cstring> #include <queue> #include <algorithm> #pragma comment(linker, "/STACK:102400000,102400000") typed...

CY05627的博客 275

【DRAM存储器六十一】LPDDR5介绍--LPDDR5/5X/4/4X IO结构

简述LPDDR5/5X/4/4X IO结构及等效电路下的VREF理论值计算

highman110的博客 480

POJ 3159 Candies(最短路 差分约束)

Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 31848 Accepted: 8896 DescriptionDuring the kindergarten days, flymouse was the monitor of his class. Occasionally the

Twillz的博客 381

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Candies POJ - 3159 (最短路+差分约束)

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 t...

weixin_30367945的博客 152

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

K - Candies (差分约束+最短路)

有n个孩子,m个关系;关系分别有3个数u,v,w。代表v的糖果数不能多于u    w个,也就是dis[v]&lt;=dis[u]+w;这就转换成 if(dis[v]&gt;dis[u]+w)            dis[v]=dis[u]+w. 1:SPFA+stack #include&lt;iostream&gt; #include&lt;queue&gt; #include&lt;...

cherish_lin的博客 262

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

POJ3159 Candies【差分约束+最短路】

Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 38621   Accepted: 10891 Description During the kindergarten days, flymouse was the monitor of his class. Occasio...

逐梦者 386

最短路径__Candies ( Poj )

Poj 3159

YzlCoder的记事本 1250

0 or 1(最短路转化)

Description Given a n*n matrix C ij (1<=i,j<=n),We want to find a n*n matrix X ij (1<=i,j<=n),which is 0 or 1. Besides,X ij meets the following conditions: 1.X 12+X 13+…X 1n=1 2.X 1n+X 2n+…X n-1n=1

Techay的博客 1101

Tram(转换为最短路模型)

Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going out of the in

Techay的博客 750

Sentry Robots

We need to guard a set of points of interest using sentry robots that can not move or turn. We can position a sentry at any position facing either north, south, east or west. Once a sentry is settled

Techay的博客 713

The Shortest Path in Nya Graph(神一样的建图)

Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this para

Techay的博客 687

Layout(差束约分系统)

Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows

Techay的博客 686

昂贵的聘礼(坑爹的枚举+bellmanford)

Description 年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:”嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。”探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,

Techay的博客 660

Lift Hopping

Ted the bellhop: “I’m coming up and if there isn’t a dead body by the time I get there, I’ll make one myself. You!” Robert Rodriguez, “Four Rooms.” A skyscraper has no more than 100 floors, numbere

Techay的博客 632

Calling Circles

If you’ve seen television commercials for long-distance phone companies lately, you’ve noticed that many companies have been spending a lot of money trying to convince people that they provide the be

Techay的博客 624
上一篇: Party at Hali-Bula(树形dp)
下一篇: Subway(最短路)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值