ZOJ 3946 Highway Project (spfa)

ATM火控电容改造实战:提升速凌无刷电机动力与系统稳定性 在嵌入式系统与电机驱动领域,电源完整性是保障电路稳定运行的核心基础。其核心原理在于通过合理的电容网络设计,为负载提供瞬时大电流并滤除高频噪声,从而维持电压稳定。这项技术的核心价值在于能显著提升系统的动态响应能力与可靠性,避免因电压跌落导致微控制器复位或功率器件过应力。典型的应用场景包括无人机电调、机器人关节驱动以及各类需要快速响应的伺服系统。本文聚焦于水弹发射器ATM火控系统的硬件迭代,通过详解电容的选型、布局与焊接流程,特别是针对速凌五代无刷电机的高启动电流特性,系统性地阐述了如何通过强化电源储能与芯片去 阅读详情

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5718

Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project.

The Marjar Empire has N cities (including the capital), indexed from 0 to N - 1 (the capital is 0) and there are M highways can be built. Building the i-th highway costs Ci dollars. It takes Di minutes to travel between city Xi and Yi on the i-th highway.

Edward wants to find a construction plan with minimal total time needed to reach other cities from the capital, i.e. the sum of minimal time needed to travel from the capital to city i (1 ≤ i ≤ N). Among all feasible plans, Edward wants to select the plan with minimal cost. Please help him to finish this task.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first contains two integers N, M (1 ≤ N, M ≤ 105).

Then followed by M lines, each line contains four integers Xi, Yi, Di, Ci (0 ≤ Xi, Yi < N, 0 < Di, Ci < 105).

Output

For each test case, output two integers indicating the minimal total time and the minimal cost for the highway project when the total time is minimized.

Sample Input
2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 1 1
2 3 1 2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 2 1
2 3 1 2

Sample Output
4 3
4 4


0~n-1个城市,然后可以修M条路。走完每条路要Di的时间,修这条路要Ci的花费。
然后让你修一些路使其满足从0到其他每个城市的总的时间花费最短。在这个条件满足的情况下下,找总的最小的花费。


解法: 依题意得,求每个点到0这个点的最短路径,明显spfa。
利用贪心的思想,取每个点的入边的最小花费,相加可得答案。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int M = 1e5 + 100;
const long long INF = 0x3f3f3f3f;
typedef long long ll;
struct Node{
    int next,to;
    ll d,c;
    Node(){}
    Node(int a,int b,ll d,ll c):next(a),to(b),d(d),c(c){}
}Edge[M*2];
int head[M]; int nedges; ll dis[M];
ll in[M],vis[M];
void add_edge(int a,int b,ll c,ll d)
{
    Edge[++nedges] = Node(head[a],b,c,d);
    head[a] = nedges;
    Edge[++nedges] = Node(head[b],a,c,d);
    head[b] = nedges;
}
void spfa(int n)
{
    queue<int>que;
    dis[0] = 0;
    que.push(0);
    vis[0] = true;
    while(!que.empty())
    {
        int now = que.front();
        que.pop();
        vis[now] = false;

        for(int i = head[now];~i;i=Edge[i].next)
        {
            int v = Edge[i].to;
            if(dis[now] + Edge[i].d <= dis[v])
            {
                if(dis[now] + Edge[i].d == dis[v])
                   in[v] = min(in[v],Edge[i].c);
                else in[v] = Edge[i].c;
                dis[v] = dis[now] + Edge[i].d;
                if(!vis[v])
                {
                    que.push(v);
                    vis[v] = true;
                }
            }
        }
    }
    ll nowl = 0,nowr = 0;
    for(int i=1;i<n;i++) nowl += dis[i],nowr += in[i];
    printf("%lld %lld\n",nowl,nowr);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        nedges = -1;
        memset(head,-1,sizeof(head));
        memset(dis,INF,sizeof(dis));
        memset(vis,false,sizeof(vis));
        memset(in,INF,sizeof(in));
        scanf("%d%d",&n,&m);
        while(m--)
        {
            int x,y;
            ll d,c;
            scanf("%d%d %lld%lld",&x,&y,&d,&c);
            add_edge(x,y,d,c);
        }
        spfa(n);
    }
    return 0;
}
【UE5】映射方式:动作映射(Action Mappings) 与 轴映射(Axis Mappings) 链接:https://pan.baidu.com/s/1nQHvZXC4BDsfbFWDYZqEfA?按下键盘A键,不要抬起,屏幕左上角打印了一次。(和Unity中的轴映射机制类似)下面我们通过测试更直观的了解一下这。抬起键盘A键,屏幕左上角打印了一次。项目资源文末百度网盘自取。再添加一个按键,选择键盘。键,缩放值设置为 2.0。,框选所有测试节点,按下。的情况下,屏幕一直打印。 阅读详情

相关推荐

动态刷新曲线_【GhPython应用】利用反射刷新Image sampler组件

【版权声明】| 作者:月之眼|案例图片来源:Sergiu Radu Pop的facebook| 如有侵权,请联系大水牛平台|如果觉得文章不错,欢迎分享效果展示利用python刷新Image sampler组件,主要的思路就是X输入端:输入要切换的图片路径,我的案例中输入了9张图片。然后通过100毫秒切换一张图片显示,来达到动态显示效果。代码分析run输入端类型:bool (I...

weixin_42393829的博客 534

ZOJ 3946 Highway Project【spfa】

Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from th

希望的专栏 664

LangChain与SkillLite集成:AI Agent安全沙箱实践

在AI与自动化技术领域,安全沙箱是实现可信计算的核心机制。其原理是通过资源隔离与权限控制,构建受限的执行环境。技术价值在于平衡功能开放性与系统安全性,尤其适用于处理用户提交的非受信代码或敏感数据。典型应用场景包括AI插件系统、在线代码评测平台等。本文以LangChain框架与SkillLite沙箱的深度集成为例,详解如何通过命名空间隔离、cgroups限制等机制,为AI Agent赋予安全执行动态技能的能力。其中涉及的关键技术点包括Python运行时隔离、动态资源配额管理,以及如何防范Shell注入等常见攻

weixin_34189116的博客 407

ZOJ 3946 Highway Project SPFA 两个限制条件

点击打开链接 题意:一个帝国有 n 个城市,可以在城市两两之间建立 m 条高速公路,建立  x-y            之间的高速路需要时间 d,花费为 c,最后建立完边(            号城市到各个城市(1--n-1)的总时间最少,在多个时间满足条件下再选花            费最少的。 分析:最短路             。首要条件是花费时间

became_a_wolf的专栏 501

手把手教你学SOME/IP「1.0•概述」

本文介绍了SOME/IP协议的基本概念和主要特点。SOME/IP全称为"Scalable service-Oriented MiddlewarE over IP",是一种面向服务的车载嵌入式通信协议,支持远程过程调用、事件通知等功能。文章指出SOME/IP是AUTOSAR标准的一部分,在车载以太网架构中处于应用层位置,负责服务调度和通信封装。协议具有可扩展性强、资源消耗低、兼容性好等优势,能满足汽车电子领域对实时性、可靠性的严格要求。同时,文章也说明了SOME/IP的正确书写规范,并解释

nihaoljq2010的博客 681

YOLOv8/v9实战:从零搭建智慧零售货架管理系统(附完整可运行代码)

摘要:本文基于YOLOv8/v9目标检测算法,详细讲解智慧零售货架管理系统的开发流程,解决传统人工巡检效率低、漏检率高的问题。内容涵盖环境配置、商品检测、陈列分析、价格标签验证等核心功能实现,提供可运行代码及零售专用数据集训练方法。系统支持实时货架状态监控、缺货预警与数据分析,帮助零售企业降低运营成本30%以上。 关键词:YOLOv8、YOLOv9、智慧零售、货架管理、商品检测 标签:YOLOv8、YOLOv9、目标检测、零售AI、Python

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1313

zoj 3946 Highway Project(最短路径)

题目链接 题意:最短路径,每个边上有2个权值,第二个权值是不能累加的#include<bits/stdc++.h>using namespace std;#define LL long long #define cl(a,b) memset(a,b,sizeof(a)) #define pb push_back #define gcd __gcdconst int maxn = 100005; c

qwesde 801

SQL Server数据库备份与恢复

在 SQL Server 中,数据库备份与恢复是保障数据安全的核心操作。

zjw541806的博客 1884

ZOJ3946 Highway Project(spfa,最短路变形)

描述 Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway ...

riba2534的博客 622

C/C++小宇宙代码(完整代码)

C语言实现小宇宙的完整代码。

AIGC 2530

ThingsBoard集群部署之k8s

今天终于有时间去搞这个啦,拖了很久了,一直没时间,因为我本地没有那么多机器资源,开虚拟机不够,如果租用阿里云服务器,需要有充值的时间,因为这个费用是按小时付费,需要有连贯的时间来搞才行,今天恰好有时间,就开始搞了,弄成功搞出来了,特地写博客记录下来。

AldrichEugene 1177

ZOJ 3946(单源最短路)

//题意:给定n个点,m条路,每条路的花费为d,消耗的时间为c // 求从起点到各个点的时间之和最小且花费最小 //方法:spfa跑一遍并维护cost 答案会爆int 有点坑 #include #include #include #include #define error 999999999 using namespace std; int fir[100100], vis

Below_Crusder的博客 621

YOLO11改进 | 注意力机制 | 添加SimAM注意力机制【全网独家+附完整代码】

yolo11,yolo11改进,yolo11创新,yolo11添加注意力机制

kay_545 1241

Highway Project (ZOJ - 3946,双权值 spfa)

一.题目链接: ZOJ-3946 二.题目大意: T 组数据. 第一行两个整数 n,m 之后 m 行数据,每行给出第 i 条路的 {起点,终点,花费时间,花费金钱} 首都为第 0 号城市. 求从首都到其他所有城市所需的 总时间 和 总建路花费. 三.分析: 双权值的单源最短路,更改 if 条件语句里就可以了. 注意:时间可重复加,但花费不可以. 所以直接用 dis2[v...

The___Flash的博客 306

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

zoj 3946 Highway Project【SPFA多个性质的最优化】

Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from t

dxx_111的博客 789

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

K - Highway Project  ZOJ - 3946 【 SPFA 求最小时间下最小距离】

K - Highway Project ZOJ - 3946 Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he...

Mercury_Lc的博客 578

zoj 3946 Highway Project (spfa + 最小生成树)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5718 Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build

大太阳 883

Word界面优化:一键隐藏导航窗格与高效排版工具推荐

在文档处理与办公软件应用中,界面布局优化是提升工作效率的基础技术。其原理在于通过自定义视图设置,减少非核心元素的视觉干扰,从而扩大有效编辑区域。这一技术的核心价值在于帮助用户实现更专注的写作状态,尤其适用于长文档编辑、学术论文撰写等需要深度专注的场景。通过掌握快捷键操作和视图管理,用户可以灵活控制导航窗格等辅助工具的显示与隐藏,实现工作界面的动态优化。本文聚焦于Microsoft Word这一主流工具,详细介绍了隐藏右侧导航窗格的多种实用方法,并自然融入了样式管理和第三方排版工具的应用建议,为文档处理流程的

weixin_34355559的博客 343

(spfa) Highway Project (zoj 3946 )

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5718 Highway Project Time Limit:2 Seconds Memory Limit:65536 KB Edward, the emperor of the Marjar Empire, wants to ...

weixin_30950607的博客 61

zoj--3946--Highway Project(SPFA)

Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from t

playboy307 410

ZOJ 3946 Highway Project(spfa最短路+记忆化搜索)

Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from t

每一次AC都是一种感动 735

ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA

ZOJ Problem Set - 3946 Highway ProjectTime Limit:2 Seconds Memory Limit:65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach othe...

weixin_30261095的博客 113

ZOJ 3946 Highway Project(最短路)

题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题面: Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wan

David_Jett 1156

zoj 3946 Highway Project

我TM建个前向星的双向边MAXN只开100005???还一直不报WA,一直以为我是哪里没考虑到。。。。 一定要注意数组大小了。思路很简单,从0到其他点的最短路距离是一定的,那要求最小花费,那就边跑最短路边更新最小花费呗。 #include<cstdio> #include<cstdlib> #include<iostream> #incl...

133

ZOJ 3946 Highway Project

题目链接:http://icpc.moe/onlinejudge/showProblem.do?problemId=5718 第13届浙江省省赛的题目,题意是给我们一些边的距离与花费,让我们求出所有点到起点(0)的所有最短路距离和,以及达到最短路情况的花费总和,我们采取的思路是先SPFA算出所有点的最短路径,再根据最短路径得出所有可能会建的边,在这些边中找到花费最小的。 注意一点,就是我们的最

RaAlGhul的博客 562

zoj3946--Highway Project

Highway ProjectTime Limit: 2 Seconds Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the...

dixi7825的博客 197

ZOJ-3946-Highway Project(最短路)

Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from

不会吃鱼的喵 807
上一篇: CDOJ 1092 韩爷的梦 (字符串Double Hash)
下一篇: 2016 UESTC Training for Data Structures
WANSNIM
博客等级 码龄12年 27粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值