poj 3259 Wormholes

题目连接

http://poj.org/problem?id=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 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

spfa判断负环。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using std::map;
using std::min;
using std::find;
using std::pair;
using std::queue;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 510;
const int INF = 0x3f3f3f3f;
struct SPFA {
    struct edge { int to, w, next; }G[N * 10];
    bool vis[N];
    int tot, inq[N], head[N], dist[N];
    inline void init(int n) {
        tot = 0;
        rep(i, n + 1) {
            head[i] = -1;
            inq[i] = vis[i] = 0;
            dist[i] = INF;
        }
    }
    inline void add_edge(int u, int v, int w) {
        G[tot] = (edge){ v, w, head[u] }; head[u] = tot++;
    }
    inline void built(int m, int w) {
        int u, v, x;
        while(m--) {
            scanf("%d %d %d", &u, &v, &x);
            add_edge(u, v, x), add_edge(v, u, x);
        }
        while(w--) {
            scanf("%d %d %d", &u, &v, &x);
            add_edge(u, v, -x);
        }
    }
    inline bool spfa(int n, int s = 1) {
        queue<int> q;
        q.push(s);
        dist[s] = 0, vis[s] = true;
        while(!q.empty()) {
            int u = q.front(); q.pop();
            vis[u] = false;
            for(int i = head[u]; ~i; i = G[i].next) {
                edge &e = G[i];
                if(dist[e.to] > dist[u] + e.w) {
                    dist[e.to] = dist[u] + e.w;
                    if(!vis[e.to]) {
                        vis[e.to] = true;
                        q.push(e.to);
                        inq[e.to]++;
                    }
                }
                if(inq[e.to] > n) return true;
            }
        }
        return false;
    }
    inline void solve(int n, int m, int w) {
        init(n), built(m, w);
        puts(spfa(n) ? "YES" : "NO");
    }
}go;
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    int t, n, m, w;
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d %d", &n, &m, &w);
        go.solve(n, m, w);
    }
    return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4773490.html

利用正射影像对斜射图像进行反向投影 因此,RANSAC算法可以通过计算inliners和outliers的数量来评估估计关键点的质量,确保与其他点不一致的点不会在Homography矩阵中被估计。然后,它通过考虑关键点周围区域中图像的梯度大小和方向来计算每个提取的关键点的方向。由于单应性矩阵的计算可能会受到两个图像中异常值的存在的影响,这将导致矩阵的不正确估计并导致沿图像的对准和映射不良。FLANN匹配器的方法基于K近邻搜索的概念,即从图像中找到k个近邻。找到相机在正射影像坐标系中的位置并在正射影像上绘制重叠区域的边界框。 阅读详情

相关推荐

一种基于OpenPose和DNN的跌倒检测软件系统(中文&英文)

学习并实现一种跌倒检测模型,此模型基于OpenPose实现逐帧人体姿态检测,使用DNN识别人体动作。检测方式有在线与离线两种,本文主要测试了离线模式,测试效果较好。

Tongzhou_Li的博客 2644

POJ3259——Wormholes

题目链接:http://poj.org/problem?id=3259 Wormholes 题目大意:给你n个点,m条双向联通的权值为正的路,和w条单向联通权值为负的路。让你判断是否存在负环。 用队列实现,判断是否存在负环。 #include #include #include #include #define INF 0xfffffff using namespace std; c

piaocoder 400

触摸屏蓝牙控制

使用杰理芯片通过蓝牙实现触摸屏功能,需要结合触摸屏数据采集、蓝牙数据传输以及移动端应用的实现。

m0_46145044的博客 1109

POJ 3259 Wormholes【Bellman-Ford】

http://poj.org/problem?id=3259POJ 3259 Wormholes大意:给出由n个顶点组成的有向图所有边信息,判断该图中是否存在负回路分析: 由于不知道图中的负环路会包含哪些顶点,故自定义一源点s,对于每个顶点k,有一条s到k权值为0的有向边,此时便可初始化s到每个顶点的距离dis[k]为0,然后用Bellman-Ford计算从源点s到各点的単源最短路,若...

a48634331的博客 161

Tessy学习系列(三):单元测试——官方例程isValueInRange

注意:工程名称以及路劲不能包含空格和中文

不吃鱼的猫的博客 2347

Deepseek:物理神经网络PINN入门教程

物理信息网络(Physics-Informed Neural Networks, PINN)是一种将物理定律(如偏微分方程、守恒定律等)嵌入神经网络训练过程的深度学习方法。其核心思想是通过神经网络同时拟合观测数据并满足物理约束,从而解决传统数值方法难以处理的高维、噪声数据或复杂边界条件问题。

金石软件 9298

POJ 3259 Wormholes

POJ 3259 Wormholes[★★☆☆☆]图论 最短路 bellman 题目大意:本质就是求该图是否存在负环。也就是如何求出一个图是否含有负环。 要注意的是输入该题中的path是双向的,wormhole是单向的 样例输入: 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输出: NO YES 解题思路:这

Stay hungry... 810

半导体硅制造工艺

抛光液和硅片的反应速度很快,只要稍一停留,立刻便会腐蚀,因此取片时,不能在表面上留下抛光液,必须紧接着水抛,直至抛光液被全部冲去,再将片子取下。由于晶圆制造过程有各种各样的晶圆固定器和自动设备,需要严格的直径控制以减少晶圆翘曲和破碎,而单晶硅棒的外径表面并不平整且直径也比最终抛光晶片所规定的直径规格大,因此需要通过外径滚磨获得较为精确的直径。胶体的颗粒直径比磨料的颗粒直径小一个数量级,且硬度与硅相当,因此它比用磨料的机械抛光表面损伤更小,抛光出的硅片表面具有高度的镜面光洁。不受材料导电类型和电阻率的影响。

pgpaojiao的博客 2240

[POJ3259](最短路spfa)Wormholes

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

Z7784562的博客 249

SAP 与 Palantir 合作全景解析:这不是普通集成,而是把 ERP、数据语义层、云迁移与企业级 AI 串成一条价值链

SAP与Palantir的战略合作聚焦企业数字化转型核心痛点,通过深度技术整合构建"数据-决策-执行"闭环。合作包含四大主线:云迁移连续性保障、SAP业务数据云与Palantir平台对接、联合工程开发、高监管行业优先落地。技术实现上采用SAP认证插件,支持双向数据交互和实时业务动作触发。该合作突破了传统ERP系统局限,将业务语义与AI执行相结合,特别适合制造业供应链优化、财务争议处理等高价值场景,为企业在云迁移过程中实现业务连续性与智能化升级提供新范式。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 192

译码器Multisim电路仿真汇总——硬件工程师笔记

本文详细介绍了74LS139D和74LS138D两种TTL译码器的功能特点及应用。74LS139D是2线-4线译码器,具有低电平有效输出和使能控制功能,常用于地址译码和数据分配。74LS138D是3线-8线译码器,通过3位输入实现8路输出控制,广泛应用于微处理器系统。文中提供了两种芯片的引脚说明、真值表和典型应用电路,并附有硬件工程师笔试面试相关资源链接。这些基础知识对数字电路设计和硬件工程师面试准备具有重要参考价值。

XU157303764的博客 1260

Wormholes POJ - 3259【最短路】

Wormholes POJ - 3259 题目 思路:能见到几秒前的自己说明存在负环,直接spfa判断负环,记得每次都把数组邻接表…之类的初始化 注意:起点不一定是从1开始的,所以每个点都应该作为入队起点 具体代码如下 #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int N = 510, M = 6000;

qq_50702668的博客 203

【ComfyUI】QwenImageEdit OOTD角色与姿态匹配换装

本文介绍了一个基于Qwen Edit OOTD 2.0的ComfyUI工作流,能够实现角色与姿态匹配的智能穿搭生成。该工作流通过整合模型推理、姿态识别、图像拼接和渲染等节点,完成从角色图、姿态图到成品穿搭图的完整生成流程。核心采用Qwen Image系列模型进行图像理解和编辑,配合ControlNet进行姿态引导。用户只需提供角色图和姿态参考图,系统即可自动完成姿态解析、语义编码、采样生成等步骤,输出与输入姿态一致的穿搭图像。该方案适用于虚拟角色展示、电商试穿等场景,能保持角色特征一致的同时灵活变换姿态,显

Mr数据杨 1584

【POJ 3259】Wormholes

【POJ 3259】Wormholes 判断负环——BellMan/SPFA代码如下BellMan-Ford

ACMer' 882

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

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

POJ3259 Wormholes 【spfa判负环】

题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit:2000MS Memory Limit:65536K Total Submissions:75598 Accepted:28136 Description While exploring his ma...

a6334167的博客 153

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

POJ3259 Wormholes Floyd判负圈

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

Bill_Utada的成长之路 1203

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

poj 3259 Wormholes(Bellman-Ford)

poj 3259 WormholesDescriptionWhile 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

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 900

POJ-3259-Wormholes

POJ-3259-Wormholes http://poj.org/problem?id=3259 bellman_ford判断是否有负环 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cstdlib&gt; using namespace std; #define M...

java开发指南博客 【转载】 182

POJ 3259—Wormholes

题下:POJ 3259—Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 66356 Accepted: 24748 Description While exploring his many farms, Farmer John has discovered a number of amazing wor...

wanglin007 310

【POJ 3259 --- Wormholes】Bellman-Ford, 负权回路

【POJ 3259 --- Wormholes】Bellman-Ford, 负权回路 题目来源:点击进入【POJ 3259 — Wormholes】 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very pecu...

来日浅谈的博客 514

POJ 3259 Wormholes (最短路 SPFA 判断负环)

POJ 3259 Wormholes (最短路 SPFA 判断负环) 题意: N个农场旅行 有M个路径 和 W个虫洞。 有M行 普通路径 S ,E, T。表示从地点S(E)到地点E(S)的时间为T。接着有W行为虫洞。普通路径是双向的, 虫洞是单向,且为负值 思路:既有虫洞又有普通道路,把虫洞看成是一条负权路,问题就转化成 求一个图中是否存在负权回路 。 定义一个数组记录入队次数,每个元素 入队次数是否小于 N 。

jianjun的专栏 518

POJ 3259 Wormholes

链接: POJ 3259  Wormholes                  Ural

天下有码 386

POJ 3259 -- Wormholes

POJ 3259 -- Wormholes   农夫约翰在探索他的许多农场,发现了一些惊人的虫洞。虫洞是很奇特的,因为它是一个单向通道,可让你进入虫洞的前达到目的地!他的N(1≤N≤500)个农场被编号为1..N,之间有M(1≤M≤2500)条路径,W(1≤W≤200)个虫洞。FJ作为一个狂热的时间旅行的爱好者,他要做到以下几点:开始在一个区域,通过一些路径和虫洞旅行,他要回到最开时出发的那个区...

weixin_30388677的博客 138

POJ 刷题系列:3259. Wormholes

POJ 刷题系列:3259. Wormholes传送门:3259. Wormholes题意: N个顶点,任意顶点之间存在双向边,权重为正,也可能存在单向边(虫洞),权重为负。给出一张图,问是否存在负环。 思路:重新回顾了下Bellman-Ford算法,核心思路如下:从单个源点出发,如果经过N轮还在更新时,说明存在负环。证明:假设不存在负环,那么最短路径必然不会经过一个顶点两次,所以最多通过N-

Demon-初来驾到 893
上一篇: poj 3080 Blue Jeans
下一篇: poj 3281 Dining
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值