poj 3268 Silver Cow Party(最短路+SPFA)

能碳双控| AIRIOT智慧能碳管理解决方案 基于AIRIOT打造的智慧能碳管理平台解决方案结合大数据、物联网、人工智能(AI)、数字孪生等新一代信息技术,通过整合碳达峰、碳中和、实时碳价、碳配额和碳资产等多个模块,为组织提供了全方位、灵活且智能的碳资产管理解决方案,有助于实现碳管理目标、提升可持续性,并适应碳市场的不断变化。 阅读详情

Silver Cow Party
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9514 Accepted: 4263

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:  N,  M, and  X 
Lines 2.. M+1: Line  i+1 describes road  i with three space-separated integers:  Ai,  Bi, 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


思路:所有出边算次最短路,然后在改成入边算次最短路,加和最大就是答案。我用SPFA


失误:不知道为什么用vector 数组传不进来,郁闷。


#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int nn=1010;
const int mm=100009;
const int oo=1e9;
class node
{
  public:int v,c;
  node*nex;
  node(){nex=NULL;}
}*edge[nn],*redge[nn];

bool vis[nn];
int dis[nn],cost[nn];
int n,m,t;
queue<int>q;
void spfa(node*e[])
{
   for(int i=0;i<=n;i++)
    dis[i]=oo;
   memset(vis,0,sizeof(vis));
   int z;node*ptr;
   dis[t]=0;
   q.push(t);vis[t]=1;
   while(!q.empty())
   {
     z=q.front();q.pop();vis[z]=0;
     ptr=e[z];
     while(ptr!=NULL)
     {
       if(dis[ptr->v]>dis[z]+ptr->c)
       {
         dis[ptr->v]=dis[z]+ptr->c;
         if(!vis[ptr->v])
         {
           q.push(ptr->v);vis[ptr->v]=1;
         }
       }
       ptr=ptr->nex;
     }
     /*for(int i=0;i<e[z].size();i++)
     {
       if(dis[e[i].v]>dis[z]+e[i].c)
       {
         dis[e[i].v]=dis[z]+e[i].c;
         if(!vis[e[i].v])
          q.push(e[i].v),vis[e[i].v]=1;
       }
     }*/
   }
}
int main()
{
  while(cin>>n>>m>>t)
  {
    memset(edge,0,sizeof(edge));
    memset(redge,0,sizeof(redge));
    memset(cost,0,sizeof(cost));
    int a,b,c;node*z;
    for(int i=0;i<m;i++)
    {
      cin>>a>>b>>c;
      z=new node();z->v=b;z->c=c;
      z->nex=edge[a];edge[a]=z;
      z=new node();z->v=a;z->c=c;
      z->nex=redge[b];redge[b]=z;
    }
    spfa(edge);
    for(int i=1;i<=n;i++)
    {
      cost[i]=dis[i];
    }
    spfa(redge);int ans=0;
    for(int i=1;i<=n;i++)
    { if(dis[i]==oo||cost[i]==oo)continue;
      cost[i]+=dis[i];if(cost[i]>ans)ans=cost[i];
    }
    cout<<ans<<"\n";
  }
}





【C语言】一文搞懂C语言文件操作 读写文件、文件相关库函数详解、文件缓冲区介绍 阅读详情

相关推荐

基于单片机控制双向可控硅灯光强度设计

*单片机设计介绍,基于单片机控制双向可控硅灯光强度设计。

QQ2193276455的博客 2457

[kuangbin]专题四 最短路练习 Silver Cow Party POJ - 3268【dijkstra】

【题目描述】 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-...

inv0ker的博客 219

基于深度学习的图像去雨(Opencv,Pytorch,Cnn)

最近做了一个图像去雨项目,使用的语言为Python,深度学习框架为Pytorch。去雨效果不错,具体请看效果视频!图像去雨(GAN,Opencv,Pytorch)

Czqqwer的博客 2612

POJ - 3268 Silver Cow Party (dijkstra求多个点到一个点最短路径的小技巧)

Silver Cow PartyTime Limit: 2000MS Memory Limit: 65536DescriptionOne 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__1998的博客 592

告别枯燥的Unity编辑器脚本:Odin插件如何让游戏数据配置变得像搭积木一样简单?

本文详细介绍了Odin插件如何简化Unity编辑器脚本开发,使游戏数据配置变得直观高效。通过声明式特性和丰富的可视化工具,Odin让开发者告别繁琐的OnGUI代码,实现所见即所得的开发体验。文章重点展示了Odin的核心优势、魔法特性及实战案例,帮助Unity开发者提升工作效率。

weixin_28717411的博客 345

SAP-ABAP:SAP库存管理核心增强:IF_EX_MB_DOCUMENT_BADI 深度解析

SAP库存管理核心增强:IF_EX_MB_DOCUMENT_BADI 深度解析

baidu_35680696的博客 1446

POJ-3682-Silver Cow Party问题(Dijkstra算法求解)

文章目录Silver Cow Party问题题目初步探索算法思路正确算法思路解题代码 Silver Cow Party问题 题目 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 (

省洗发水钱买书 391

Android 15.0 app进程保活白名单功能实现

在15.0的系统rom产品开发中,在某些重要的app即使进入后台,产品需求要求也不想被系统杀掉进程,需要app长时间保活,就是app进程保活白名单功能的实现, 所以需要在系统杀进程的时候不杀掉白名单的进程,接下来就看怎么样来实现这些功能

安卓兼职framework和app工程师的博客 638

POJ 3268 迪杰斯特拉图论 置换找最短路

题目:https://vjudge.net/problem/POJ-3268 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...

weixin_30872671的博客 159

【精品5万字图文详解】特征平台建设方案与最佳实践

关键词:特征工程、特征平台、特征存储、特征服务、机器学习、数据工程摘要:本文全面介绍了特征平台的建设方案与最佳实践,从特征工程的基本概念出发,深入剖析了特征平台的核心组件、架构设计和实现方法。文章通过生动的类比和实例,使读者能够轻松理解特征工程的重要性及特征平台如何解决企业在机器学习过程中面临的数据管理挑战。同时,详细探讨了主流开源特征平台的对比分析、系统设计要点、实际落地案例以及未来发展趋势,为企业构建高效特征平台提供了全面的指导和参考。想象一下,小明是一位热爱烹饪的小学生。有一天,他想做一道美味的菜肴送

AI天才研究院 952

【学习系列】SAP RAP 22:Excel文件上传和读取(非扩展&扩展方式)

本文介绍了在RAP中实现Excel文件上传处理的三种方法:1) 使用@Semantics.largeObject注解实现简单上传下载,但限制在ObjectPage页面使用;2) 通过自定义action弹窗实现上传功能,但存在无法自动刷新列表等限制;3) 结合CustomUIExtension实现更灵活的完整功能,但需要UI5开发技能。文章详细说明了每种方法的实现步骤,包括数据库表设计、注解配置、前端界面开发和后端处理逻辑,并比较了各自的优缺点。最后通过一个处理不同币种数据的示例,展示了如何实现业务处理逻辑。

DeveloperMrMeng的博客 623

POJ - 3268 Silver Cow Party (俩遍最短路)

题目描述: 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-

AC即性感 365

**YOLOv11性能突破:基于YOLOv10-PSA注意力机制的目标检测革命性升级**

购买即可解锁300+YOLO优化文章,并且还有海量深度学习复现项目,价格仅需两杯奶茶的钱,别人有的本专栏也有!

m0_71589036的博客 195

Silver Cow Party POJ - 3268 (最短路 spfa)

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 r

Top_xiao的博客 249

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

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

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

POJ-3268 Silver Cow Party(最短路spfa算法)

POJ-3268 Silver Cow PartySilver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19989 Accepted: 9128DescriptionOne cow from each of N farms (1 ≤ N ≤ 1000) convenientl

废宅工程狮养成日志 421

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ3268 Silver Cow Party spfa求解 最短路

题意:有N个点M条边,农场间由M条有向路径连接。每头牛来回都走最短的路,求这些牛中来回的最大时间? 分析:做两次spfa,一次以X为源点到每头牛,再一次从每头牛到X,求出每头牛来回的最大时间即使答案。 #include #include #include #include #include #include const int INF=0x3f3f3f3f; typedef long long

小萨摩的博客 450

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

POJ 3268 Silver Cow Party (来回最短路 SPFA)

POJ 3268 Silver Cow Party (来回最短路 SPFA)

Tc的专栏 1146

POJ 3268 - Silver Cow Party(链式前向星正反建图 + 两次最短路spfa)

来自 N (1 ≤ N ≤ 1000)个农场的奶牛的编号分别为1,2, … ,N。现在在农场 X (1 ≤ X ≤ N) 举行聚会。总共有 M (1 ≤ M ≤ 100,000) 条单向通道。路 i 需要时间 Ti 才能通过。每头牛都需要参加聚会并返回,而且它们均选择花费时间最短的路线。 问:在所有的奶牛中,所花费的最长时间为多少? Input 第一行包含三个整数N,M,X。 在接下来的M行中,每行都包括三个整数A,B和T,表示从农场A到B需要花费时间T。 Output 输出奶牛所花的最大时间。 Sampl

在读NLP硕士 181

文章标题 POJ 3268 : Silver Cow Party (最短路--spfa)

Silver Cow PartyOne 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) unidirectio

Wang_SF2015的博客 352

poj-3268 Silver Cow Party (最短路-spfa-求到同一起点,同一终点的最短路)

Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23716   Accepted: 10826 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently

Lee_w_j__的博客 413

POJ - 3268 Silver Cow Party SPFA+SLF优化 单源起点终点最短路

Silver Cow Party One cow from each ofNfarms (1 ≤N≤ 1000) conveniently numbered 1..Nis going to attend the big cow party to be held at farm #X(1 ≤X≤N). A total ofM(1 ≤M≤ 100,000) unidir...

weixin_30697239的博客 97

poj 3268 Silver Cow Party(最短路)

poj 3268 Silver Cow PartyDescription 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

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

D - Silver Cow Party POJ - 3268——————最短路+思维(两遍单元最短路)

题目连接 https://vjudge.net/contest/313997#problem/D 大体思路: 这个题用floyd 会T的 所以就要 顺这跑一边最短路, 逆着跑一边最短路 详细思路+代码 /****** 题目要求: 是 询问 最快来回一趟, 耗时最大的那头牛所用的时间 两边单源最短路就行 ①首先可以求出 从聚会点返回到牛棚的最短路径【这个你们都会】 ②从牛棚去的时候的最短路径就是...

T.J的博客 249

POJ 3268 Silver Cow Party (最短路径)

POJ 3268 Silver Cow Party (最短路径) 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...

dipinzhu4111的博客 157

POJ 3268 Silver Cow Party

题目描述: 有N(1≤N≤1000)个农场,编号为1~N,每个农场有一头奶牛。这些奶牛将参加在#X(1≤X ≤N)号农场举行的派对。这N 个农场之间有M(1≤M≤100,000)条单向路,通过第i 条路将需要 花费Ti(1≤Ti≤100)单位时间。 每头奶牛必须走着去参加派对。派对开完以后,返回到它的农场。每头奶牛都很懒,所以总 是选择一条具有最短时间的最优路。每头奶牛的往返路线是不一样

Paradiser 1164

Silver Cow Party--poj3268(SPFA)

Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15533   Accepted: 7045 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently

Eric_keke的专栏 830
上一篇: poj 2240 Arbitrage(最短路+Bellman-Ford)
下一篇: poj 3259 Wormholes(最短路+spfa+判负回路)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值