H. Holy Grail(The Preliminary Contest for ICPC Asia Nanjing 2019题解)
题目链接As the current heir of a wizarding family with a long history,unfortunately, you find yourself forced to participate in the cruel Holy Grail War which has a reincarnation of sixty years.However,fortunately,you summoned a Caster Servant with a powerful Noble Phantasm.When your servant launch her Noble Phantasm,it will construct a magic field,which is actually adirectedgraphconsisting ofn verticesandm edges.More specifically,the graph satisfies the following restrictions :Does not have multiple edges(for each pair of verticesxandy, there is at most one edge between this pair of vertices in the graph) and does not have self-loops(edges connecting the vertex with itself).May havenegative-weighted edges.Does not have anegative-weighted loop.n300,m500.Currently,as your servants Master,as long as you add extra6edges to the graph,you will beat the other 6 masters to win the Holy Grail.Howeveryou are subject to the following restrictions when you add the edges to the graph:Each time you add an edge whose cost is c,it will cost you c units of Magic Value.Therefore,you need to add an edge which has the lowest weight(its probably that you need to add an edge which has a negative weight).Each time you add an edge to the graph,the graph must not have negative loops,otherwise you will be engulfed by the Holy Grail you summon.InputInput data contains multiple test cases. The first line of input contains integert— the number of testcases (1≤t≤5).For each test case,the first line contains two integers n,m,the number of vertices in the graph, the initial number of edges in the graph.Then m lines follow, each line contains three integersx, y and w(0≤x,yn,-10^9≤w≤10^9, x​y) denoting an edge from vertices x to y (0-indexed) of weight w.Then 6 lines follow, each line contains two integerss,tdenotingthe starting vertexandthe ending vertexof the edge you need to add to the graph.It is guaranteed that there is not an edge starting froms to tbefore you add any edges and there must exists such an edge which has the lowest weight and satisfies the above restrictions, meaning the solution absolutely exists for each query.OutputFor each test case,output 666 lines.Each line contains the weight of the edge you add to the graph.INPUT 1 10 15 4 7 10 7 6 3 5 3 3 1 4 11 0 6 20 9 8 25 3 0 9 1 2 15 9 0 27 5 2 0 7 3 -5 1 7 21 5 0 1 9 3 16 1 8 4 4 1 0 3 6 9 2 1 8 7 0 4 OUTPUT -11 -9 -45 -15 17 7题意n个点m条边给出m条边的起点终点和权值最后给出6组数x,y要求在x到y上加权值问所加权值最小为多少加边满足加完之后不能有负环加完立即生效。思路直接找y到x的最短路取相反值即可因为这样不会有负环。因为有负边所以用SPFA。#includestdio.h #includealgorithm #includeiostream #includeset #includemap #includestring #includestring.h #includemath.h #includevector #includequeue #define maxn 150000 #define ll long long #define inf 0x3f3f3f3f using namespace std; ll dis[500]; int vis[500]; struct A { int to; ll w; }; vector A v[500]; void SPFA(ll s) { queue int q; memset(dis,inf,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[s]0; vis[s]1; q.push(s); while(!q.empty()) { int uq.front(); q.pop(); vis[u]0; for(int i0;iv[u].size();i) { int xv[u][i].to; ll yv[u][i].w; if(dis[u]ydis[x]) { dis[x]dis[u]y; if(vis[x]0) { q.push(x); vis[x]1; } } } } return ; } int main() { int t; scanf(%d,t); while(t--){ int n,m,a,b; ll c; struct A t; scanf(%d%d,n,m); for(int i1;im;i){ scanf(%d %d %lld,a,b,c); t.to b; t.w c; v[a].push_back(t); } for(int i0;i6;i){ scanf(%d %d,a,b); SPFA(b); ll ans dis[a]; t.to b; t.w (-1)*ans; v[a].push_back(t); printf(%lld\n,(-1)*ans); } for(int i0;in;i){ v[i].clear(); } } return 0; }

相关新闻

HS2-HF Patch:15分钟解锁Honey Select 2完整游戏体验的终极指南

HS2-HF Patch:15分钟解锁Honey Select 2完整游戏体验的终极指南

HS2-HF Patch:15分钟解锁Honey Select 2完整游戏体验的终极指南 【免费下载链接】HS2-HF_Patch Automatically translate, uncensor and update HoneySelect2! 项目地址: https://gitcode.com/gh_mirrors/hs/HS2-HF_Patch HS2-HF Patch是专为Honey Select 2 …

2026/7/28 14:10:48阅读更多 →
Linux运维新手入门:从零搭建Zabbix监控与Docker容器化实战

Linux运维新手入门:从零搭建Zabbix监控与Docker容器化实战

这次我们来看一个面向零基础新手的 Linux 运维工程师全技能学习路径。对于想入行或转行运维的朋友来说,最头疼的往往不是某个技术有多难,而是不知道从何学起、学哪些、学到什么程度才算入门。这篇文章将直接切入核心,为你梳理出一条从 Linux 基础到企业级监控、容器化、数据…

2026/7/28 14:10:48阅读更多 →
Unity红点系统设计:从性能优化到架构解耦的实战指南

Unity红点系统设计:从性能优化到架构解耦的实战指南

1. 项目概述:红点系统,一个被低估的“性能刺客” 在Unity游戏开发,尤其是手游和重度运营类项目中,UI界面上的小红点几乎是标配。它安静地躺在按钮、图标、头像的右上角,提示着玩家“这里有新内容”、“这里有奖励待领取…

2026/7/28 14:10:48阅读更多 →
获取dom元素操作整理

获取dom元素操作整理

文章目录获取元素属性和方法方法jQuery方法属性jQuery方法增删改操作创建添加克隆删除jQuery方法自定义属性jQuery修改样式jQuery方法document可以获取的盒子模型属性js盒子模型获取指定元素的 CSS 样式jQuery方法获取元素属性和方法 整理与参考 方法 document.getElementBy…

2026/7/28 15:21:23阅读更多 →
JackSon  jar包下载

JackSon jar包下载

JackSonjar包下载。 原文博主链接:https://blog.csdn.net/qq_42390424/article/details/86759792 ———————————————— 版权声明:本文为CSDN博主「LicoLeung」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文…

2026/7/28 15:21:23阅读更多 →
计算机毕业设计之基于springboot的个人提升系统的设计与实现

计算机毕业设计之基于springboot的个人提升系统的设计与实现

随着大数据、人工智能的快速发展,传统的手工管理方式已难以满足现代用户的需求。为了提升工作效率、优化用户体验并降低运营成本,本研究设计并实现了一套基于Spring Boot的个人提升系统。该系统充分利用Spring Boot框架的简洁性、高效性和易用性&#xf…

2026/7/28 15:21:23阅读更多 →
spring设计模式-单例模式

spring设计模式-单例模式

单例模式 :是指确保一个类在任何情况下都绝对只有一个实例,并提供一个全局访问点。单例模式是创建型模式 懒汉式单例模式:在类加载的时候就立即初始化,并且创建为单例对象,它绝对线程安全,线程还没出现的时…

2026/7/28 15:21:23阅读更多 →
5分钟掌握OBS多平台直播推流:obs-multi-rtmp插件完整配置指南

5分钟掌握OBS多平台直播推流:obs-multi-rtmp插件完整配置指南

5分钟掌握OBS多平台直播推流:obs-multi-rtmp插件完整配置指南 【免费下载链接】obs-multi-rtmp OBS複数サイト同時配信プラグイン 项目地址: https://gitcode.com/gh_mirrors/ob/obs-multi-rtmp 你是否曾为多平台直播而烦恼?想要同时在YouTube、B…

2026/7/28 15:21:23阅读更多 →
5分钟构建智能金融数据管道:Python量化分析的新利器

5分钟构建智能金融数据管道:Python量化分析的新利器

5分钟构建智能金融数据管道:Python量化分析的新利器 【免费下载链接】pywencai 获取同花顺问财数据 项目地址: https://gitcode.com/gh_mirrors/py/pywencai 想象一下,你正在为量化策略寻找数据源,面对复杂API文档和繁琐的爬虫代码&am…

2026/7/28 15:19:22阅读更多 →
覆盖国产 + 海外 + 开源模型,OpenClaw 2.7.9 Windows/Mac 双端部署详解

覆盖国产 + 海外 + 开源模型,OpenClaw 2.7.9 Windows/Mac 双端部署详解

🔹 工具基础介绍 OpenClaw 是开源生态中一款实用性较强的本地智能工具,凭借本地离线运行、可视化图形操作和任务自动化三大核心特性,赢得了众多用户的青睐。与普通在线对话AI工具不同,它属于能够直接操控本机软硬件的智能数字员工…

2026/7/28 4:06:39阅读更多 →
伺服阀焊完微漏毁整机?精密激光焊接三关锁住高压

伺服阀焊完微漏毁整机?精密激光焊接三关锁住高压

所谓液压伺服阀体的精密激光焊接,是用激光束对阀座壳体(通常为不锈钢或铝合金)进行密封焊接,使阀体在21-35MPa的高压液压油或压缩气体中长期运行而不发生介质泄漏。液压伺服阀是高端液压系统的"大脑"。从航空航天飞行控…

2026/7/28 2:08:06阅读更多 →
D2DX:三步实现《暗黑破坏神2》高清宽屏体验的终极指南

D2DX:三步实现《暗黑破坏神2》高清宽屏体验的终极指南

D2DX:三步实现《暗黑破坏神2》高清宽屏体验的终极指南 【免费下载链接】d2dx D2DX is a complete solution to make Diablo II run well on modern PCs, with high fps and better resolutions. 项目地址: https://gitcode.com/gh_mirrors/d2/d2dx 你是否还在…

2026/7/28 1:38:28阅读更多 →
告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿!3步让你的暗影精灵笔记本重获新生 【免费下载链接】OmenSuperHub Control Omen laptop performance, fan speeds, and keyboard lighting, and unlock power limits. 项目地址: https://gitcode.com/gh_mirrors/om/OmenSuperHub 你是否也曾为官方Om…

2026/7/28 0:00:29阅读更多 →
RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

做 RAG 的人应该都踩过这个致命的坑:把几百页的财报、法规、技术手册扔给向量库,问一个具体问题,搜出来的全是沾边但没用的内容 —— 关键信息要么被硬切块拆碎了,要么藏在几十条结果的最下面。语义相似≠真正相关,这个…

2026/7/28 0:00:29阅读更多 →
抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

2026年做短视频运营,从抖音上扒文案早就不是偷偷抄笔记的事了。我刚开始做内容的时候,每天刷半小时抖音,手动把爆款视频的口播敲进备忘录,一条2分钟的视频得花十来分钟,碰到语速快的还要反复回听。后来试了一圈工具&am…

2026/7/28 0:00:29阅读更多 →
YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

如果你在部署 YOLOv8 时,发现推理速度只有可怜的 1-2 FPS,而别人的演示视频却能跑到 30 FPS 以上,那么问题很可能不在模型本身,而在于你的整个处理链路。很多开发者拿到一个训练好的 YOLOv8 模型后,会直接使用官方示例…

2026/7/27 16:57:54阅读更多 →
Coze与Dify对比指南:低代码AI应用开发从入门到实战

Coze与Dify对比指南:低代码AI应用开发从入门到实战

1. 从零到一:为什么你需要了解 Coze 和 Dify?如果你对 AI 应用开发感兴趣,但一看到“大模型”、“智能体”、“工作流”这些词就头疼,觉得门槛太高,那这篇文章就是为你准备的。很多开发者,包括我自己&#…

2026/7/28 3:17:03阅读更多 →
AI生图工具怎么选?2026年6月版实测对比

AI生图工具怎么选?2026年6月版实测对比

做自媒体的朋友应该都有体会:配图一直是个让人头疼的问题。2026年,AI生图工具已经非常成熟了,但工具太多反而不知道怎么选。以下是截至2026年6月我对主流AI生图工具的实测对比。Midjourney V8.1:速度之王2026年6月11日&#xff0c…

2026/7/28 2:35:58阅读更多 →