Wormholes(题意抽象+SPFA判负权环)

超分算法 SwinIR: Image Restoration Using Swin Transformer 这篇文章结构比较简单,如果看过Swin-Transformer的话就没什么难点了。作者引入Swin-T结构应用于低级视觉任务,包括图像超分辨率重建、图像去噪、图像压缩伪影去除。网络由一个浅层特征提取模块、深层特征提取模块、重建模块构成。重建模块对不同的任务使用不同的结构。浅层特征提取就是一个3×3的卷积层。深层特征提取是k个RSTB块和一个卷积层构成。RSTB(Res- SwinIR: Image Restoration Using Swin Transformer[ICCV 2021]Abstract1. 阅读详情


Link:http://poj.org/problem?id=3259


Wormholes
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 36128 Accepted: 13198

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.

Source


解题思想:这题主要要理解当花费的时间为负时,说明能在起点看到原来的自己。由题意可抽象出判断给出的图中是否存在负权环,存在则输出“YES”,否则输出“NO”。输入的路的边权为正,虫洞的边权为负,而SPFA算法思想在求最短路时,只有负权环对其有影响,也就是说可利用SPFA求最短路的入队出队过程判断是否出现负环。


AC code:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#define LL long long
#define MAXN 1000010
using namespace std;
const int INF=0x3f3f3f3f;
int n,m,tot,k;
int head[MAXN];
struct node{
	int from;
	int to;
	int w;
	int next;
}edge[MAXN];
int dis[MAXN];
bool inq[MAXN];
int cnt[MAXN];
int path[MAXN];
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
void add(int from,int to,int w)
{
	edge[tot].from=from;
	edge[tot].to=to;
	edge[tot].w=w;
	edge[tot].next=head[from];
	head[from]=tot++;
}
bool spfa(int st)
{
	deque<int>q;
	memset(dis,INF,sizeof(dis));
	memset(inq,false,sizeof(inq));
	memset(cnt,0,sizeof(cnt));
	dis[st]=0;
	q.push_back(st);
	inq[st]=true;
	cnt[st]++;
	while(!q.empty())
	{
		int now=q.front();
		q.pop_front();
		inq[now]=false;
		if(cnt[now]>=n)
		{
			return false;//注意:SPFA求最短路时是对存在负权环有影响,因为会一直入队一直循环下去,
		}				//而存在正权环无影响,因为求最短路是递减的过程,正权环不会一直绕下去,但负权环会,
						//而利用SPFA求最长路时正好相反。  
		for(int i=head[now];i!=-1;i=edge[i].next)
		{
			int nex=edge[i].to;
			if(dis[nex]>dis[now]+edge[i].w)
			{
				dis[nex]=dis[now]+edge[i].w;
				if(!inq[nex])
				{
					inq[nex]=true;
					cnt[nex]++;
					if(!q.empty()&&dis[nex]<dis[q.front()])
					{
						q.push_front(nex);
					}
					else
					{
						q.push_back(nex);
					}
				}
			}
		}
	}
	return true;//不存在负权环,返回true 
}
int main()
{
	//freopen("D:\in.txt","r",stdin);
	int T,cas,i,j,u,v,w;
	scanf("%d",&T);
	for(cas=1;cas<=T;cas++)
	{
		scanf("%d%d%d",&n,&m,&k);
		init();
		while(m--)
		{
			scanf("%d%d%d",&u,&v,&w);
			add(u,v,w);
			add(v,u,w);
		}
		while(k--)
		{
			scanf("%d%d%d",&u,&v,&w);
			add(u,v,-w);
		}
		if(spfa(1))
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		 }  
	}
	return 0;
 } 



IEC61850规约客户端软件开发实战(第二章) 本文介绍了基于IEC61850规约的客户端软件开发过程,重点阐述功能界面设计和服务端连接功能的实现。界面采用Qt框架设计,包含功能按钮区、数据模型展示区(使用QTreeWidget)和状态显示区。连接功能通过libiec61850开源库实现,详细说明了连接流程、句柄创建及状态管理的代码实现。测试结果表明系统能正确识别连接状态,并通过界面直观显示。文章为IEC61850规约软件开发提供了实用参考,下期将分享规约模型数据加载的实现过程。 阅读详情

相关推荐

网易CodeWave智能生成应用实战:5分钟搞定库存管理系统(附详细配置截图)

本文详细介绍了如何利用网易CodeWave智能生成应用在5分钟内快速构建定制化库存管理系统。通过自然语言描述需求,无需编程即可生成包含产品管理、库存预警等核心功能的应用,并支持字段微调、业务流程注入等深度优化。文章附有详细配置截图,帮助用户高效实现数字化转型。

julia4scientist的博客 888

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

(超详细)Scala环境搭建(scala-2.12.15、IDEA2021.1.3)

Scala环境搭建(scala-2.12.15、IDEA2021.1.3) JunLeon——go big or go home 目录 Scala环境搭建(scala-2.12.15、IDEA2021.1.3) 一、Scala概述 1、什么是Scala? 2、Scala发展史 3、Scala与Java的关系 二、Scala环境搭建 1、环境准备 2、Scala安装与配置环境变量 3、验证Scala 三、编写第一个Scala程序 1、使用IDEA创建maven工程 2、.

JunLeon的博客 3万+

如何用 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的博客 718

QT 面试题汇总

一、讲述Qt信号槽机制与优势与不足 优点:①类型安全。需要关联的信号槽的签名必须是等同的。即信号的参数类型和参数个数同接受该信号的槽的参数类型和参数个数相同。若信号和槽签名不一致,编译器会报错。 ②松散耦合。信号和槽机制减弱了Qt对象的耦合度。激发信号的Qt对象无需知道是那个对象的那个信号槽接收它发出的信号,它只需在适当的时间发送适当的信号即可,而不需要关心是否被接受和那个对象接受了。Qt就保证了适当的槽得到了调用,即使关联的对象在运行时被删除。程序也不会奔溃。 ...

编程菜鸟 4万+

零基础搭建本地AI绘画环境:Stable Diffusion 3.5保姆级安装教程(含中文优化方案)

本文提供零基础搭建本地AI绘画环境的详细教程,重点介绍Stable Diffusion 3.5的安装与中文优化方案。从硬件配置检查到软件依赖安装,再到核心组件配置与中文语义增强,教程涵盖全流程操作指南,帮助用户快速掌握AI文生图模型的本地部署技巧,提升创作效率。

weixin_30752699的博客 312

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的博客 1645

面向干净核心的并行扩展:SAP BTP 上的 side-by-side extensions 全面解读

摘要: SAP的side-by-side extensions是一种与核心系统解耦的云原生扩展模式,通过API和事件驱动实现与SAP S/4HANA等核心系统的松耦合集成。该模式支持独立升级、弹性扩展和高效创新,是SAP官方推荐的clean core关键实现路径。其典型架构包括接口层(OData/REST API、事件通道)、运行层(Cloud Foundry/Kyma/CAP框架)和体验层(Fiori/UI5)。适用场景包括需快速迭代、复用云服务或服务外部用户的业务扩展。实施时需关注安全治理(如XSUAA

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

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

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

Strive 590

YOLO26 无损剪枝:稀疏训练 + 结构化通道裁剪

YOLO26 无损剪枝链路:YOLO26s (7.2M) → 稀疏训练 30 epoch (L1 on BN gamma, lam=0.01) → 阈值剪枝 50% (gamma<quantile(0.5)) → 结构化重建 Conv+BN → 微调 10 epoch (lr=1e-4) → YOLO26n (1.9M, mAP50 0.808, 仅降 0.6%)。核心贡献:稀疏训练让 BN gamma 趋向二元分布 (近 0 或近 1), 剪枝阈值可直接取 median 自动 50% 压缩。

m0_64661770的博客 263

14003.xilinx系统移植

文章目录1 xilinx 系统移植 sd卡版本1.1 创建项目1.2 拷贝 *.hdf 到工程目录1.3 根据hdf文件对系统进行配置1.3.1 设置内核源码路径为本地1.3.2 设置分区的名称与大小1.4 清除本地缓存并编译成功1.5 打包生成BOOT.BIN并拷贝到sd卡1.6 问题1.7 系统启动成功1.8 配置设备树文件丰富系统外设 1 xilinx 系统移植 sd卡版本 芯片型号 ZYNQ UltraScale+ XAZU2EG ,对应厂家提供的demo板为 zu102或zu104 1.1 创建

写给自己的笔记 483

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

人生如戏 231

爬虫:一文掌握网站加密和混淆以及浏览器调试的技巧

面对加密和混淆技术的网站,传统的爬虫方法可能难以奏效。通过结合浏览器调试工具(如Puppeteer、Playwright)、代理工具(如Burp Suite、Fiddler)以及动态和静态分析技巧,可以深入理解网站的运行机制,绕过加密和混淆,实现有效的数据抓取。同时,务必注意合法合规,尊重目标网站的规则和用户的隐私,确保爬虫行为的正当性和可持续性。

数据知道的博客 9891

POJ 3259 - Wormholes(SPFA判负环)

题目描述 教学楼里有很多教室,这些教室由双向走廊连接。另外,还存在一些单向的秘密通道,通过它们可以回到过去。现在有 N (1 ≤ N ≤ 500) 个教室,编号 1…N, M (1 ≤ M ≤ 2500) 条走廊,和 W (1 ≤ W ≤ 200) 条秘密通道。 DY在养猫之余,还是一个时间旅行爱好者。她希望从一间教室出发,经过一些走廊和秘密通道,回到她出发之前的某个时间。 共有F (1 ≤ F ≤ 5) 组数据。对每组数据,判断DY是否有回到过去的可能性。不存在耗时超过10,000秒的走廊,且不存在能带D

在读NLP硕士 243

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

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

qq_37087993的博客 338

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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

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

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

[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的博客 264

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 destination at a time that i

zitian246的博客 3463

Wormholes POJ - 3259 (Bellman算法判负环)

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

alex1997222的博客 218

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

qq_43735840的博客 264

Wormholes 虫洞(floyed求最短路)

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 time that is BEFORE you entere...

m0_58245389的博客 465

Bellman-ford算法详解——负权环分析

算法描述 输入:图(V,E)和起点original 输出:从original到其他任意节点的最短路径(长度和最短路径构成) 适用条件 Bellman-ford算法适用于单源最短路径,图中边的权重可为负数即负权边,但不可以出现负权环。 负权边:权重为负数的边。 负权环:源点到源点的一个环,环上权重和为负数。 算法复杂度:O(VE) 算法步骤 dist[]:从o...

anlian523的博客 2万+

图论 —— 环与块 —— 负权环

【概述】 从一个点出发,经过一条简单路径回到起点,称为图的环,而图的负权环就是环中所有的边的权值均为负值。 所谓负权环问题,就是判断图中是否存在一个环,且这个环上的各边的权值均为负。 【Bellman-Ford 算法】 Bellman-Ford 算法在计算单源最短路径时可以判断是否存在负环 关于 Bellman-Ford 算法:点击这里 int n,w,m; int dis[N]; ...

Alex_McAvoy的博客 2138

Wormholes ---Bellman-Ford算法 最短路径 负权值回路判断 (POJ3259)

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

SYITwin的博客 636

Wormholes(负权回路)

点击打开链接 Problem 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 i

765
上一篇: Easter Holidays(二次spfa求最短路、最长路+打印路径)
下一篇: 矩阵快速幂专题(矩阵快速幂入门、矩阵构造法、数论规律题)
林下的码路
博客等级 码龄12年 295粉丝 506原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值