发布时间:2026/7/28 14:09:57
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; }

相关新闻

2026/7/28 14:04:56

5分钟快速上手:GoldHEN金手指管理器终极使用指南

5分钟快速上手:GoldHEN金手指管理器终极使用指南 【免费下载链接】GoldHEN_Cheat_Manager GoldHEN Cheats Manager 项目地址: https://gitcode.com/gh_mirrors/go/GoldHEN_Cheat_Manager GoldHEN金手指管理器是专为PlayStation 4玩家设计的开源作弊代码管理工…

2026/7/28 14:04:56

304不锈钢耐腐蚀防火门 滨海高盐雾车间防爆防火通道门

304不锈钢耐腐蚀防火门是专为滨海区域、化工厂区、高盐雾潮湿环境研发的专用消防设备,拥有完整消防认证,适配工业车间、防爆通道、厂区楼道、户外消防通道等场景,有效解决普通钢制防火门易生锈、腐蚀、老化变形的难题,是沿海工程项…

2026/7/28 14:04:56

防火推拉窗优势

防火推拉窗是兼具消防防火功能与日常通风采光的特种消防门窗,区别于传统平开防火窗,推拉开启结构设计更贴合现代建筑大洞口、大空间使用需求,广泛应用于厂房、仓库、机房、地下室、商业综合体等场所,综合使用优势十分突出。该窗最…

2026/7/28 15:15:27

CZSC缠论插件:3步快速部署的终极通达信智能交易解决方案

CZSC缠论插件:3步快速部署的终极通达信智能交易解决方案 【免费下载链接】Indicator 通达信缠论可视化分析插件 项目地址: https://gitcode.com/gh_mirrors/ind/Indicator CZSC缠论可视化交易插件是一款专为通达信软件设计的开源缠论分析工具,将复…

2026/7/28 15:15:27

物联网安全:硬件安全元件SE050的应用与集成

1. 物联网安全现状与硬件安全元件的必要性物联网设备的安全威胁正在呈现指数级增长态势。根据最新的行业安全报告,2023年全球物联网设备遭受的攻击次数同比增加了87%,其中针对工业控制系统的针对性攻击占比高达42%。传统基于软件的安全方案在面对物理侧信…

2026/7/28 15:15:27

Google AI Overviews 43%覆盖率深度解析:AI搜索RAG系统架构、GEO生成式引擎优化与搜索引擎的范式革命

一、引言:AI搜索正在成为默认入口 2026年7月,Similarweb发布的最新数据显示,Google AI Overviews在搜索结果中的出现率从一年前的15%飙升至43%,AI Mode的月访问量从2025年6月的1.26亿增长到2026年5月的2.79亿,翻了一倍以上。这意味着AI搜索已经不再是可选的附加功能,而是…

2026/7/28 15:15:27

突破平台壁垒:在Windows原生运行安卓应用的创新方案

突破平台壁垒:在Windows原生运行安卓应用的创新方案 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 你是否曾想过在Windows系统上直接运行安卓应用&#xf…

2026/7/28 15:10:26

高效设计转代码:Marketch插件让Sketch设计稿秒变网页

高效设计转代码:Marketch插件让Sketch设计稿秒变网页 【免费下载链接】marketch Marketch is a Sketch 3 plug-in for automatically generating html page that can measure and get CSS styles on it. 项目地址: https://gitcode.com/gh_mirrors/ma/marketch …

2026/7/28 13:41:25

PDF合并与动态水印的工程化方案:2026国内免费工具实测对比

一、背景与测试方案 在实际项目交付中,PDF文件合并与版权保护水印的叠加是一个高频但容易被低估的技术需求。典型的处理链路涉及:多源PDF的文件流合并、页面级水印渲染(含透明度混合与图层叠加)、输出文件体积控制。看似简单的操作…

2026/7/28 0:03:34

学术论文研究创新点梳理与核心价值提炼指南

本科毕业论文是大学四年最大的坎。开题报告憋一周写不出三页,找文献翻遍十几个网站还是缺关键资料,写正文卡壳半天憋不出一句话,降重改到凌晨三点结果逻辑全乱,答辩前一天PPT还没做完。别慌,亲测这四个工具能让你少熬半…

2026/7/28 0:03:34

开发商售楼处数字化升级怎么做?

房企的数字化转型投入正在快速增长,据行业数据显示,2025年房企数字化投入规模已突破800亿元,年复合增长率达35%。售楼处的数字化升级不是单一环节的改造,而是从“获客-展示-成交-服务”全链路的系统升级。数字化升级四步法第一步&…

2026/7/28 0:03:34

模型不再值钱之后,AI 编程工具在争什么

2026 年 7 月,AI 编程工具赛道发生了一个标志性转折:模型本身不再值钱了。当 Kimi K3 开源模型在编程基准上击败 GPT 和 Claude,当 GitHub Copilot 第一次把开源模型纳入选择器,当 OpenAI 把 Codex 并入 ChatGPT 做成三合一超级应…

2026/7/28 4:38:09

3个高效策略:快速掌握Axure中文界面配置

3个高效策略:快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…