【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】

2024-08-31 16:48

本文主要是介绍【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Silver Cow Party
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 15522 Accepted: 7039

Description

One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.

Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.

Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?

Input

Line 1: Three space-separated integers, respectively:  NM, and  X 
Lines 2.. M+1: Line  i+1 describes road  i with three space-separated integers:  AiBi, and  Ti. The described road runs from farm  Ai to farm  Bi, requiring  Ti time units to traverse.

Output

Line 1: One integer: the maximum of time any one cow must walk.

Sample Input

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

Sample Output

10

Hint

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.

Source

USACO 2007 February Silver

sizeof() 失效


#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;int N,M,X;
int g[1010][1010];
int d1[1010];
int d2[1010];
bool vis[1010];
const int INF = 0x7fffffff/100;
void dij(int g[1010][1010],int d[1010])
{rep(i,0,N) d[i] = INF;memset(vis,0,sizeof(vis));d[X] = 0;rep(i,0,N-1){int dmin = INF;int p = -1;rep(j,0,N) {if(!vis[j] &&  d[j] < dmin){dmin = d[j];p = j;}}vis[p] = true;rep(j,0,N) {if(!vis[j] && d[j] > d[p] + g[p][j]){d[j] = d[p] + g[p][j];}}}
}void travs()
{rep(i,0,N) rep(j,i,N) {int tmp = g[i][j];g[i][j] = g[j][i];g[j][i] = tmp;}
}
int main()
{while(scanf("%d%d%d",&N,&M,&X) != EOF){X --;rep(i,0,N) rep(j,0,N) g[i][j] = INF;rep(i,0,M) {int u,v,w;scanf("%d%d%d",&u,&v,&w);u--,v--;g[u][v] = min(g[u][v],w);}dij(g,d1);travs();dij(g,d2);int maxs = -1;for(int i=0;i<N;i++){if(maxs < d1[i] + d2[i]){maxs = d1[i] + d2[i];}}printf("%d\n",maxs);}return 0;
}


这篇关于【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1124448

相关文章

Linux如何做ssh反向代理

SSH反向代理是一种通过SSH协议实现的安全远程访问方式,它允许客户端通过SSH连接到一台具有公网IP的代理服务器,然后这台代理服务器再将请求转发给内部网络中的目标主机。以下是实现SSH反向代理的步骤: 一、准备工作 确保服务器配置: 内网服务器(目标主机)和外网服务器(代理服务器)都安装了SSH服务,并且能够通过SSH进行互相访问。内网服务器上的服务(如Web服务、数据库服务等)需要在本地

Nginx反向代理功能及动静分离实现

一:Nginx支持正向代理和反向代理 1.正向代理 正向代理,指的是通过代理服务器 代理浏览器/客户端去重定向请求访问到目标服务器 的一种代理服务。 正向代理服务的特点是代理服务器 代理的对象是浏览器/客户端,也就是对于目标服务器 来说浏览器/客户端是隐藏的。 正向代理是客户端指定让代理去访问哪个服务,代表客户端的利益。 2.反向代理 反向代理,指的是浏览器/客户端并不知道自己要

ider文件查找功能失效

在ider中,配置快速查找文件为ctrl+shift+R(Eclipse风格),有时明明类存在,却搜索不到,这时可以清除idea缓存并重启试试: 第一步:点击 File 选择 Invalidate Caches/Restart 第二步:

Form 表单的 resetFields() 失效原因

假设我们有如下代码:  <template><ElForm ref="formRef" :model="formModel" :rules="rules"><!-- 表单内容 --></ElForm></template><script setup>import { ref } from 'vue';const formRef = ref(null);const formModel = ref

GDB 反向调试

使用调试器时最常用的功能就是step, next, continue,这几个调试命令都是“往下执行”的, 但是很多时候会有这种需求:你在调试的过程中多跳过了几步而错过中间过程,这时候不得不重头调试一遍,非常麻烦。而GDB从7.0版本开始支持反向调试功能,也就是允许你倒退着运行程序,或者说撤销程序执行的步骤从而会到以前的状态。   直观地来看,加入你正在使用GDB7.0以上版本的调试器并且运行在

【佳学基因检测】网站加密证书失效后,如何移除并为新的证书安装准备环境?

【佳学基因检测】网站加密证书失效后,如何移除并为新的证书安装准备环境? 当WoTrus DV Server CA证书失效后,你需要确保你的Nginx配置中不再引用该证书,并且移除或替换相关的证书文件。以下是具体步骤: 1. 确认Nginx配置文件 首先,检查Nginx的配置文件,确保它不再引用旧的WoTrus证书。如果你已经使用Certbot安装了Let’s Encrypt证书,Certbo

wx.chooseMessageFile在pc端微信小程序失效解决方法

项目场景: 在uniapp上驱动微信开发者工具(下图) 在手机上和微信开发者工具中(图1)都可以上传成功, 打开pc端的微信小程序 在pc端打开小程序时点击上传没反应 问题描述 提示:这里描述项目中遇到的问题: 在pc端打开小程序上传的时候发现点击上传没有反应,通过(    console.log("打印====111")    )打印步骤发现wx.chooseM

sql 中使用like%、函数导致索引失效的解决方案

SELECTp1.*FROM cdr_voice_202407_0 AS p1 WHERELENGTH( p1.calling_number ) < 11 AND p1.calling_number LIKE '%10086%' 上边的sql中如果 calling_number  是索引  会导致索引失效 涉及的 WHERE 子句有两个条件: LENGTH(p1.calling_numbe

android:navigationBarColor失效

android:navigationBarColor失效。 上结论,是项目引入了setupdesign设计,GlifLayout相关联的自定义布局overrride了NavigationBar主题,需要用setupdesign自定义的属性来设置颜色。 <item name="android:navigationBarColor">@color/black</item><item name="

代理服务器介绍,正向代理(校园网,vpn,http隧道技术),反向代理(公司服务器,frp服务),NAT和代理服务器的相同/不同点

目录 代理服务器 介绍 类型  正向代理 引入 介绍  vpn http隧道技术 反向代理 引入 隧道技术 介绍 frp服务 NAT和代理服务器 相同点 不同点 NAT 代理服务器 代理服务器 介绍 一种中间服务器,充当客户端(如个人计算机或移动设备)与目标服务器(如网站服务器)之间的中介 它接受客户端的请求,然后将这些请求转发给目标服务器,再把