Wormholes(负权回路)

POJ3259-Wormholes【Bellman】 北大POJ3259-Wormholes【Bellman】 解题报告+AC代码 立即下载
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 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 toF (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, <i>F</i>. <i>F</i> farm descriptions follow.< br>Line 1 of each farm: Three space-separated integers respectively: <i>N</i>, <i>M</i>, and <i>W</i>< br>Lines 2..<i>M</i>+1 of each farm: Three space-separated numbers (<i>S</i>, <i>E</i>, <i>T</i>) that describe, respectively: a bidirectional path between <i>S</i> and <i>E</i> that requires <i>T</i> seconds to traverse. Two fields might be connected by more than one path.< br>Lines <i>M</i>+2..<i>M</i>+<i>W</i>+1 of each farm: Three space-separated numbers (<i>S</i>, <i>E</i>, <i>T</i>) that describe, respectively: A one way path from <i>S</i> to <i>E</i> that also moves the traveler back <i>T</i> seconds.
 

Output
Lines 1..<i>F</i>: 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
 题意:给你n个点,m条路,最后的 num个黑洞路径,后面的m条路输入的是a-->b的距离,还有花费的时间,num个黑洞可以让你从a-->b倒回时间t,问你有没有可能在哪个点会遇到原来的自己。很有意思的一道题啊,典型的判断是不是负权回路啊。
这也是做判断是不是负权回路的第一个题,收钱二重循环一遍,然后在循环的时候发现还有dis[e]>dis[s]+x[e][s]的时候就存在赋权回路

#if 0
#include<iostream>
#include<cstring>
using namespace std;
int n,m,no,k;   //点,路,黑洞 
struct lu
{
	int a,b,t;
}mapp[10000];
int dis[10000];         

void ford_one()
{
		memset(dis,0x7f,sizeof(dis));
		dis[1]=0; 
		int a,b,t;
		for(int i=1; i<=n-1; i++)
		{	
			bool flag=0;
			for(int j=1; j<=k; j++)
			{
				a=mapp[j].a; 
				b=mapp[j].b;
				t=mapp[j].t;
				
				if(dis[b]>dis[a]+mapp[j].t)
				{
					dis[b]=dis[a]+mapp[j].t;
					flag=1;
				}
			}
			if(flag==0)
				break;
		}
}

int ford_two()
{
	int a,b,t;
	
	    
		for(int j=1; j<=k; j++)
		{
			a=mapp[j].a; b=mapp[j].b;t=mapp[j].t;
			if(dis[b]>dis[a]+mapp[j].t)
				return 1;
		}
	
	return 0;
}


int main()
{
	int T;

	cin>>T;
	while(T--)
	{
		
		cin>>n>>m>>no; 
		k=0;
		for(int i=1; i<=m; i++) 
		{
			int aa,bb,xx;
			cin>>aa>>bb>>xx;
			k++;
			mapp[k].a=aa;
			mapp[k].b=bb;
			mapp[k].t=xx;
			k+=1;
			mapp[k].a=bb;
			mapp[k].b=aa;
			mapp[k].t=xx;
		}
		
		for(int i=1; i<=no; i++)
		{
			int aa,bb,xx;
			cin>>aa>>bb>>xx;
			k+=1;
			mapp[k].a=aa;
			mapp[k].b=bb;
			mapp[k].t=-xx;
		 
		}
		
		ford_one();
		
		if(ford_two())
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
	
}
#endif 




推荐系统公平性之流行度偏差(fairness in recommender systems -- popularity bias) 主要参考论文:《The Unfairness of Popularity Bias in Recommendation》 RMSE@RecSys 2019 流行度偏差是什么 先定义流行物品和非流行物品。下图是(Movielens 1M)数据集中物品的评分情况。 图的横坐标表示不同物品,纵坐标表示物品的评分次数。可以看出只有少部分物品得到了很多的评分,大部分曲线尾部的物品都只有少量的评分,我们也把这部分物品称为长尾物品。在本文中,我们取曲线的前20%对应的物品为流行物品,剩余的为非流行物品(长尾物品)。 然 阅读详情

相关推荐

问题解决:打开VMware创建的虚拟机,电脑立刻蓝屏并重启

VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credenti

weixin_55118477的博客 3万+

Wormholes(bellman-ford)

每个农场第一行:分别是三个空格隔开的整数:N,M和W 第2行到M+1行:三个空格分开的数字(S,E,T)描述,分别为:需要T秒走过S和E之间的双向路径。第M +2到M+ W+1行:三个空格分开的数字(S,E,T)描述虫洞,描述单向路径,S到E且回溯T秒。农夫约翰在探索他的许多农场,发现了一些惊人的虫洞。他的N(1≤N≤500)个农场被编号为1..N,之间有M(1≤M≤2500)条路径,W(1≤W≤200)个虫洞。FJ作为一个狂热的时间旅行的爱好者,他要做到以下几点:开始在一个区域,通过一些路径和虫洞旅行,

qq_73261465的博客 532

OpenWRT端口转发与NAT环回冲突的排查与解决

本文详细解析了OpenWRT路由器中端口转发与NAT环回功能冲突导致的内网访问故障。通过生活化类比阐明两者工作原理,提供从基础诊断到内核参数调整、LuCI选项配置及手动编写iptables规则的多套解决方案,并给出进阶排查思路,帮助用户彻底解决内网无法通过公网地址访问服务的常见问题。

weixin_29243279的博客 506

Wormholes(最短路径)

Language: Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45773   Accepted: 16905 Description While exploring his many farms, Farmer John

jinzk123的博客 474

TCN+iTransformer时间序列预测实战:从风电功率预测到源码解析(附完整代码)

本文深入探讨了TCN与iTransformer融合模型在时间序列预测,特别是风电功率预测中的应用。通过解析iTransformer‘倒置’视角的创新架构与TCN强大的局部时序捕捉能力,文章提供了完整的融合方案设计、源码实现及实战调优经验,旨在构建更强大的下一代预测引擎。

weixin_29062671的博客 265

linux驱动由浅入深系列:块设备驱动之一(高通eMMC分区实例)

linux驱动由浅入深系列:块设备驱动之一(高通eMMC分区实例)linux驱动由浅入深系列:块设备驱动之二(块设备驱动结构分析)块设备驱动的模型还是基本基于字符设备驱动的,可以简单理解为块设备仅仅增加了操作缓冲区,对用户请求顺序进行队列重拍等等。字符设备驱动的相关分析可以查看本博客相关的博文。 按照本博客的行文习惯,在具体分析块设备驱动代码之前,我们会从整体上了解一下研究对象的特征,以及用户空间...

Radia的专栏 1万+

Wormholes(最短路)

Wormholes(最短路) Time limit:2000 ms Memory limit:65536 kB OS:Linux judge:https://vjudge.net/contest/297882#problem/F 描述 While exploring his many farms, Farmer John has discovered a number of amazing wor...

画船听雨眠 504

上海计算机学会2020年5月月赛C++乙组T2经济普查

中国正在以前所未有的力度推进脱贫攻坚,国家计划在2020年使得在现行标准下的贫困人口实现全面脱贫,为此,需要对居民的经济状况进行普查。 题目描述 给定一个正整数n,表示人口数量。一开始,每个居民拥有的财产记为a1​,a2​,⋯,an​,财产可能发生两种变化: 一种来源于个体,由某个居民的经济活动而产生。在某个时刻,某个居民的财产会直接变成某个数值,可能升高也可能降低。 一种来源于政策,在某个时刻,国家会对财产低于某个标准线全部的居民,实施政策支持,使得他们的财产全部正好到达标准线。 给定这些变

长春高老师编程 907

Wormholes(虫洞)

题目描述:有n个点,有m条路经(双向路径)(起始位置到终止位置耗时为正),有w个虫洞(单向路径)(起始位置到终止位置耗时为负,相当于穿越),判断一个人从起始位置出发,通过虫洞回到起始位置时是否能见到自己(判断是否存在负权环)。 Description While exploring his many farms, Farmer John has discovered a number of a...

G-Howe的博客 4883

ST03N 里看不到 SE38 / SA38?别急,这不是没记录,而是被换了名字

摘要:SAP系统中SE38/SA38事务码在ST03N统计中可能"隐身",因其对话步骤被归集到对应的程序名(如SE38→RSABAPPROGRAM)。ST03N侧重工作负载聚合统计,而STAD提供短期明细记录。正确排查方法是:在ST03N中搜索程序名而非事务码,再通过STAD验证具体使用情况。这一现象在权限整改和审计中易造成误判,建议将程序名纳入常规监控,并区分ST03N(趋势分析)与STAD(事实校验)的不同用途。

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

【数据集】未来不同情景下预测数据:如人口、土地利用等

未来不同情景下预测数据:如人口、土地利用等

WW、forever的博客 2994

Wormholes

Wormholes https://vjudge.net/contest/281565#problem/D Description In the year 2163, wormholes were discovered. A wormhole is a subspace tunnel through space and time connecting two star system...

北区以北的博客 288

Misc-RAR隐写

题目来自于:XCTF的SimpleRAR,由于涉及到许多新知识,所以写篇小文子记录一下。 一、下载完后是一个压缩包。 里面就有一个flag.txt,打开之后发现有一串字符是flag is not here,而且我们查看他的文件大小,只要十六字节,绝对不可能再藏着什么信息了。 然后把压缩包拉到010editor里面,发现一下子出来好多新的内容,很明显是有夹杂着的附加文件。 二、rar文件头信息。 rar 是由一个一个 block 组成的,每个 block 有以下几个部分 ...

admin的博客 1361

【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

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

蓝牙模块HM-10手册

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

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

POJ_3259(Wormholes)(SPFA判断负权回路)

POJ_3259(Wormholes)(SPFA判断负权回路) Wormholes Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 76   Accepted Submission(s) : 31 Problem Descript

hpulw 629

IEM模型,地表粗糙度模拟

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

Poj 3259 Wormholes判断负权回路(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 that

gravi的博客 386

POJ 3259 Wormholes (寻找负权回路)

题目大意:有n个点m条双向路,w条单向路,输入的数据中前两个表示两点之间有路,前m条路表示这条路所花费的时间,后w条单向路表示可以回到过去某个时间,现在问你从某个点走之后是否会看到自己还没出发时的样子。 如果有负权回路,即一个回路中点的权值总和为负数,那么就能看到没有出发时的自己,因为自己回到了出发之前的时间。 用SPFA算法进行解,不断的松弛边,如果存在负权回路那么每一次松弛都会使距

FJUT_ACM_cjt152的博客 884

POJ3259 Wormholes SPFA负权回路判断

题目要我们求是否存在一条路,FJ重新回到起点之后时间回到了过去,就是让我们判断在图中是否存在负权回路。 我用了SPFA,当一个点入队超过n次时,可以判断图中存在负权回路。 注意图中的前m条路是双向的,注意处理 后面的w条虫洞是单向的。 Wormholes Time Limit: 2000MS   Memory Limit: 65536K

728

Wormholes (Floyd 负权回路)

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

hello_cmy的博客 2666

POJ-3259 Wormholes(负权回路[Bellman-Ford])

只以1号点为源点做Bellman-Ford即可判断图中是否存在负权回路(该负权回路不一定以1号点为起点) 例如: 1 3 0 2 2 3 1 3 2 1 这组数据会输出YES 调试时能发现,dis[2],dis[3]每次都在更新,但是是在INF的基础上更新,所以要判断1号点是否可打2,3时,要判断dis[2],dis[3]是否 大于 图中的最大权值和才行

idealism_xxm的专栏 941

【spfa求负权回路】poj 3259 Wormholes

题意:field块地,path条路,hole个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts。每条路给出起点、终点和经过时间,我们的任务是判断能否从某地出发,在过去的某个时间回到该地。 思路:即判断是否有负权回路,有的话就能回到原地。 关于SPFA:SPFA 在形式上和广度(宽度)优先搜索非常类似,不同的是bfs中一个点出了队列就不可能重新进入队列, 但是SPFA...

iroy33的博客 224

TOJ 1661 Wormholes -- 负权回路 Dijkstra

题目链接:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1661

randygx的专栏 616

POJ 3259 Wormholes SPFA 判断负权回路

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 a

旧时光 880

POJ 3259 Wormholes 【spfa 负权回路】

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

Head_Hard的博客 259

POJ 3259 Wormholes Bellman_ford负权回路

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

dengguan2720的博客 173
上一篇: Shredding Company
下一篇: Truck History(最小生成树)
Joined
博客等级 码龄10年 19粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值