poj 3259 Wormholes ([kuangbin带你飞]专题四 最短路练习)

AI辅助专利撰写实战:用Codex 30分钟生成发明专利初稿 这次我们来看一个用 Codex 从零开始撰写发明专利的实战项目。对于技术研发人员、产品经理或初创团队来说,专利申请是保护创新成果、构建技术壁垒的关键一步。然而,撰写一份高质量的专利申请书,尤其是权利要求书和说明书,往往需要专业的法律和技术语言,耗时耗力。这个项目演示了如何利用 AI 工具 Codex,在短时间内生成一份结构完整、逻辑清晰、具备授权潜力的专利申请文件初稿。 整个过程的核心不是让 AI 完全替代专利代理人,而是将其作为强大的“技术翻译”和“内容生成”助手。它能将你的技术构思、流程图、核心算法或产 阅读详情

Description

While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N, M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.

As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .

To help FJ find out whether this is possible or not, he will supply you with complete maps to F (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.

Input

Line 1: A single integer, F. F farm descriptions follow. 
Line 1 of each farm: Three space-separated integers respectively: N, M, and W 
Lines 2.. M+1 of each farm: Three space-separated numbers ( S, E, T) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path. 
Lines M+2.. M+ W+1 of each farm: Three space-separated numbers ( S, E, T) that describe, respectively: A one way path from S to E that also moves the traveler back T seconds.

Output

Lines 1.. F: For each farm, output "YES" if FJ can achieve his goal, otherwise output "NO" (do not include the quotes).

Sample Input

2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8

Sample Output

NO
YES

Hint

For farm 1, FJ cannot travel back in time. 
For farm 2, FJ could travel back in time by the cycle 1->2->3->1, arriving back at his starting location 1 second before he leaves. He could start from anywhere on the cycle to accomplish this.




题目大意:

农夫 FJ 有 N 块田地【编号 1...n】 (1<=N<=500)
        田地间有 M 条路径 【双向】(1<= M <= 2500)
        同时有 W 个孔洞,可以回到以前的一个时间点【单向】(1<= W <=200)
        问:FJ 是否能在田地中遇到以前的自己


算法:flod算法



思路: 田地间的双向路径加边,权值为正
        孔洞间的单向路径加边,权值为负【可以回到以前】
        判断有向图是否存在负环
      因为如果存在了负数环,时间就会不停的减少,
      那么 FJ 就可以回到以前更远的地方,肯定能遇到以前的自己的




<pre name="code" class="html">#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 510;
const int inf = 9999999;
struct Node{
    int u,v;
    int t;
}E[2500*2+200+10];
int d[maxn];
int c;
int n,m,w;
bool flod(){
    for(int i=1;i<maxn;i++) d[i]=inf;		
    d[1]=0;			//到某个点的时间 
    for(int i=1;i<n;i++){
            bool flag = false;

        for(int j=0;j<c;j++){
            int u=E[j].u;
            int v=E[j].v;
            int t=E[j].t;
            if(d[v]>d[u]+t){		//g跟新每个点时间 
                d[v]=d[u]+t;
                flag = true;
            }
        }
        if(!flag) return false;		//如果不能跟新则不存在负边 
    }
    for(int i=0;i<c;i++){
        if(d[E[i].v]>d[E[i].u]+E[i].t) return true;
    }
    return false;
}



int main(){
    int f;
    scanf("%d",&f);
    while(f--){

        scanf("%d%d%d",&n,&m,&w);
        c=0;
        for(int i=0;i<m;i++){		//m条双向正边 
            int u,v,t;
            scanf("%d%d%d",&u,&v,&t);
            E[c].u=u;
            E[c].v=v;
            E[c].t=t;
            c++;
            E[c].u=v;
            E[c].v=u;
            E[c].t=t;
            c++;
        }
        for(int i=0;i<w;i++){		//w条单向负边 
            int u,v,t;
            scanf("%d%d%d",&u,&v,&t);
            E[c].u=u;
            E[c].v=v;
            E[c].t=-t;
            c++;
        }
        if(flod()){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    return 0;
}



告别 Python!C# 直接跑 YOLO 目标检测:工控机边缘推理终极方案 set;set;set;set;set;stringget;set;get;set;get;set;get;set;get;set;告别 Python 依赖,不是排斥 Python 的训练能力,而是为了工程化的极致。在工控机这个资源受限、稳定性要求极高的战场上,是目前最优雅、最高效的解决方案。更少的依赖= 更少的故障点。更快的速度= 更高的产线节拍。更简单的部署= 更低的人力成本。现在,拿起你的 C# 项目,导入那个.onnx。 阅读详情

相关推荐

gRPC之gRPC开发流程与入门案例

gRPC之gRPC开发流程与入门案例

YIYIYI 3765

poj 3259 Wormholes——弗洛伊德判断是否存在负环

Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of F

随意凯的博客 1150

利用LTspice设计Pt100测温电路

是一种广泛使用的温度传感器,它属于(RTD, Resistance Temperature Detector)的类型,通常用于温度测量。在0°C时,的电阻值为100欧姆,且它的电阻值会随着温度的升高而升高。PT100热电阻温度阻值对应表)因此可以根据这一特性来检测出环境温度。

2301_77033628的博客 2427

如何用 floyd 算法 解决从一个出发再回到这个顶点的负权值问题

1.题目引入: While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ'

weixin_52914088的博客 719

07. 基础实战篇 - STP的基本配置

STP(生成数协议)是一个用于在局域网中消除环路的协议,他的标准是IEEE802.1d。STP通过强制使部分冗余链路处于阻塞状态,其它链路处于转发状态,将环形网络结构修剪成无环路的树形网络结构。可实现消除环路,当处于转发状态的链路不可用时,STP重新配置网络,并激活合适的备用链路状态,恢复网络连通性。

weixin_39868387的博客 7232

Qt上位机实战:5步搞定STM32 IAP固件升级(附拖拽文件处理技巧)

本文详细介绍了如何使用Qt开发STM32 IAP固件升级上位机。通过五个核心步骤,包括理解IAP机制、搭建Qt环境、实现拖拽文件加载、封装串口通信以及设计可靠通信协议,帮助开发者快速构建一个稳定、易用且支持图形化操作的固件升级工具,显著提升嵌入式产品开发与维护效率。

ss78901的博客 1093

F - Wormholes(判断是否存在负环)

##题目描述 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time...

逐梦er的博客 1647

Cadence Virtuoso ADE L保姆级教程:从DC到Noise,一次搞定6种仿真设置

本文提供Cadence Virtuoso ADE L的全面仿真教程,涵盖DC工作点分析、瞬态响应、AC特性、零极点分布和噪声性能等6种仿真设置。通过详细的步骤和实用技巧,帮助工程师高效完成从基础配置到高级后处理的完整工作流,显著提升IC设计效率。

weixin_26841743的博客 618

poj 3259 Wormholes spfa判断负环

Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 64467   Accepted: 24039 Description While exploring his many farms, Farmer John has discovered a number of amaz...

人生如戏 232

dToF直方图之美

上面视频里如果你能看懂,那么就能理解对于dToF单点的测距问题,对于大部分的描述在AMS和ST里的手册都非常的详细,有疑问的可以后台来找我探讨,今天我们单纯从上层讨论成像的问题。作为dToF算法工程师,应该是对直方图敏感的,直方图的每个Count峰都会表征出问题,因为dToF的输出只有直方图,观察直方图能够逆推出dToF的很多东西,这也是大多数公司不愿意开放直方图和Raw data的缘故。以上是一个小面阵的分辨率,第一张是直方图,后面是基于直方图寻峰出来的成像ToF图,Peak图,以及噪声Noise图。

dream it possible 3005

车载仪表-功能点测试大全(超详细,细分可作测试用例)

汽车仪表系统发展经历了机械式、电气化到智能化的演变,目前全液晶仪表渗透率达73.4%。文章详细梳理了仪表功能测试要点,包括UI界面显示一致性、按键响应、FM收音、信号灯显示、USB功能、蓝牙连接、胎压监测、导航系统、WiFi投屏、倒车影像及多媒体播放等关键功能模块的测试标准。特别关注界面切换流畅度、功能稳定性及异常情况处理能力,如投屏状态下是否卡顿、导航中断后能否自动恢复等。测试覆盖了CarPlay、AndroidAuto等主流投屏方案的兼容性验证,确保各类交互场景下的系统可靠性。

weixin_51551002的博客 2081

POJ 3259——Wormholes 图论

原题如下 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its desti

say_c_box的博客 469

微信小程序 - request:fail errcode:10011 cronet_error_code:0 error_msg:network change, cancel all task请求报错

微信小程序请求接口,报request:fail errcode:10011是什么原因,uniapp微信小程序request:fail errcode:10011 cronet_error_code:0 error_msg:network change, cancel all task,微信小程序wx.request常规访问接口,有个别用户的接口请求频繁报错,UniApp 微信小程序uni.request请求接口报错:request:fail errcode:10011 的原因分析与解决方案,苹果ios,安卓

🏆 前端领域优质创作者 4577

[ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 3259 Wormholes

SPFA求负环 模板题 记得每组处理之前clear vector 1 /* *********************************************** 2 Author :Sun Yuefeng 3 Created Time :2016/10/25 18:02:02 4 File Name :A.cpp 5 *****...

weixin_30535565的博客 97

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

kuangbin 最短路专题 - POJ - 3259 Wormholes (最短路 Floyd算法)

kuangbin 最短路专题 - POJ - 3259 Wormholes (最短路 Floyd算法) Floyd原理推荐可以看看这篇:https://blog.csdn.net/m0_46272108/article/details/108919125 #include<cstdio> #include<iostream> #include<cstring> #include<string> #include<cmath> #include&

ACM-ICPC 现役(铜牌) Codeforces Rating: 2172 255

蓝牙模块HM-10手册

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

kuangbin最短路专题Wormholes POJ - 3259

kuangbin最短路专题 传送门 题面 思路 显而易见,单向通道是负边权,用bellmanford或者spfa模板就可以过了 代码 bellman_ford #include <iostream> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <cstdio> #include <queue> #in

Sivannn的博客 265

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

kuangbin专题四 F 题 负权回路(POJ 3259 Wormholes)

POJ 3259 Wormholes While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its...

aboc43983的博客 289

[kuangbin带你飞]专题四 最短路练习 F - Wormholes

POJ - 3259 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a...

weixin_40829921的博客 278

[kuangbin]专题四 最短路练习 Wormholes POJ - 3259【spfa】

【题目描述】 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time...

inv0ker的博客 202

kuangbin专题专题四 Wormholes POJ - 3259

题目链接:https://vjudge.net/problem/POJ-3259 思路:求有无负环,起点随意选就可以,因为目的只是找出有没有负环,有了负环就可以让时间一直回退,那么一定能回到当初,这里我选择从1号点开始。 1 #include <iostream> 2 #include <cstring> 3 #include <algorith...

weixin_30472035的博客 105

正权环负权环——kuangbin最短路专题总结(2)

POJ 1860 Currency Exchange POJ 3259 Wormholes POJ 2240 Arbitrage 这个是比较常见的题型了 一般就是用Bellman-Ford算法或者SPFA算法找 货币转换是找正权环看能不能钱生钱hhh 虫洞那题是找负权环看能不能和以前的自己相遇hhh 感觉这种出题都得有很神奇的脑洞 Bellman-Ford的话就是看第n次会不会发生更新,如果会则有...

qq_37087993的博客 338

[kuangbin]POJ1860 Currency Exchange POJ3259 Wormholes | 解决正负权回路

以下是会用到题目的链接 POJ1860Currency Exchange POJ3259Wormhole 以下内容需要用到最短路的spfa算法 一、引言 在这之前的总结当中,总结过不少的最短路问题,现在又碰到了新的问题,正负权回路,为什么要用这两个题当做例题来引出来呢?是因为这两个题,一个为正权回路,另一个为负权回路,其实正负权回路的原理是一样的,不过用这两个题既能练习,又能加以区分...

一只酷酷光儿的博客 590

【SPFA判负环】[kuangbin带你飞]专题四 最短路练习 F - Wormholes

  F - Wormholes  POJ - 3259  While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to ...

qq_41037114的博客 314

[kuangbin带你飞] - Wormholes (负权路)

Wormholes (负权路) 题目链接: F - Wormholes POJ - 3259 题意 有许多虫洞,可以回到过去(单向)农场主想要回到过去,给你一个图,里面包含了普通的最短路和虫洞,问你,农场主能否回到过去 思路 这是一道典型的负权最短路问题,标准的做法应该是用Bellmen_ford吧,不过,我第一次做没有使用。我在先前做Djs的时候就一直在想,如果这里面出现了负...

梦之城 206

[ACM] POJ 3259 Wormholes (bellman-ford最短路径,判断是否存在负权回路)

Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29971   Accepted: 10844 Description While exploring his many farms, Farmer John has discovered a

逆风的方向 更适合飞翔 2730

POJ - 3259 Wormholes 图最短路径 floyd邻接矩阵模板

Training 6 - A题 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination ...

xukeke12138的博客 265
上一篇: HDU 5135 Little Zu Chongzhi's Triangles (2014 ACM-ICPC广州站)
下一篇: poj 1502 MPI Maelstrom([kuangbin带你飞]专题四 最短路练习)
Strive_Buff
博客等级 码龄11年 4粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值