UVA1416 Warfare And Logistics(LA4080)(最短路,5级)

全局最小割 一个无向连通网络,去掉一个边集可以使其变成两个连通分量则这个边集就是割集;最小割集当然就权和最小的割集。 可以用最小切割最大流定理: 1.min=MAXINT,确定一个源点 2.枚举汇点 3.计算最大流,并确定当前源汇的最小割集,若比min小更新min 4.转到2直到枚举完毕 5.min即为所求输出min     不难看出复杂度很高:枚举汇点要O(n),最 阅读详情
 

Description

Download as PDF

The army of United Nations launched a new wave of air strikes on terrorist forces. The objective of the mission is to reduce enemy's logistical mobility. Each air strike will destroy a path and therefore increase the shipping cost of the shortest path between two enemy locations. The maximal damage is always desirable.

Let's assume that there are n enemy locations connected by m bidirectional paths, each with specific shipping cost. Enemy's total shipping cost is given as c = $ \sum^{​{n}}_{​{i=1}}$$ \sum^{​{n}}_{​{j=1}}$path(i, j) . Here path(i, j) is the shortest path between locations i and j . In case i and j are not connected, path(i, j) = L . Each air strike can only destroy one path. The total shipping cost after the strike is noted as c' . In order to maximized the damage to the enemy, UN's air force try to find the maximal c' - c .

Input

The first line ofeach input case consists ofthree integers: n , m , and L . 1 < n$ \le$100 , 1$ \le$m$ \le$1000 , 1$ \le$L$ \le$10$\scriptstyle \wedge$8 . Each ofthe followingm lines contains three integers: a , b , s , indicating length of the path between a and b .

Output

For each case, output the total shipping cost before the air strike and the maximal total shipping cost after the strike. Output them in one line separated by a space.

Sample Input

4  6  1000
1  3  2
1  4  4
2  1  3
2  3  3
3  4  1
4  2  2

Sample Output

28  38

 

 

思路:先进行n次最短路,算出原先的和sum_all;

           然后对于删除每一条边所影响的最短路,进行重新最短路,算出新的sum_del,

         900MS+

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
const LL oo=1e18;
const int mm=100+9;
const int nn=2000+9;
class Edge
{
  public:int v,next;LL dis;
}e[nn];
class heap
{
  public:int u;LL dis;
  bool operator <(const heap& x)const
  {
    return dis>x.dis;
  }
};
int head[mm],edge,n,m,L;
bool del[nn],vis[mm],belong[nn][mm];LL dis[mm][mm],dd[mm],sum_all,sum_del,sum_mid;
void data()
{
  memset(head,-1,sizeof(head));edge=0;
}
void add(int u,int v,LL _dis)
{
  e[edge].v=v;e[edge].dis=_dis;e[edge].next=head[u];head[u]=edge++;
}
void dijstra(LL*d,int S,bool action)
{
  memset(vis,0,sizeof(vis));
  priority_queue<heap>Q;
  for(int i=0;i<=n;++i)
    d[i]=oo;
    d[S]=0;
    Q.push((heap){S,0});
    heap z;int u,v;
    while(!Q.empty())
    {
      z=Q.top();Q.pop();
      u=z.u;
      if(vis[u])continue;vis[u]=1;
      for(int i=head[u];~i;i=e[i].next)
      { v=e[i].v;
        if(action&&del[i])continue;///i边已经删除
        if(d[v]>d[u]+e[i].dis)
        { if(!action)
          {belong[i^1][S]=belong[i][S]=1;}
          d[v]=d[u]+e[i].dis;Q.push((heap){v,d[v]});
        }
      }
    }
    if(!action)
    {
      for(int i=1;i<=n;++i)
        if(d[i]<oo)sum_all+=d[i];
        else sum_all+=L;
    }
    else
    {
      for(int i=1;i<=n;++i)
      {
        if(dis[S][i]<oo)sum_mid-=dis[S][i];
        else sum_mid-=L;///去除原边的影响
        if(d[i]<oo)sum_mid+=d[i];
        else sum_mid+=L;///加上新边
      }
    }
}
int main()
{ int a,b,c;
  while(~scanf("%d%d%d",&n,&m,&L))
  { data();
    for(int i=0;i<m;++i)
    {
      scanf("%d%d%d",&a,&b,&c);
      add(a,b,c);add(b,a,c);
    }
    sum_all=0;
    memset(del,0,sizeof(del));
    memset(belong,0,sizeof(belong));
    for(int i=1;i<=n;++i)
    dijstra(dis[i],i,0);
    sum_del=sum_all;
    for(int i=0;i<m;++i)
    { sum_mid=sum_all;
      del[i+i]=del[i+i+1]=1;
      for(int j=1;j<=n;++j)
        if(belong[i+i][j])///这个优化很关键,有点难,源点固定的最短路会改变,当且仅当最短路上的边
        dijstra(dd,j,1);///发生变动,而一条n点最短路最多n-1条边,因此最坏需要n*(n-1)次改变
      if(sum_del<sum_mid)sum_del=sum_mid;
      del[i+i]=del[i+i+1]=0;
    }
    printf("%lld %lld\n",sum_all,sum_del);
  }
  return 0;
}


 

时间序列聚类在股票市场分析中的实践与优化 时间序列聚类是一种面向动态行为建模的无监督学习方法,其核心在于通过语义感知的距离度量(如DTW)捕捉价格形态的相位弹性与结构相似性,而非依赖静态数值或标签驱动。相比K-Means等传统算法,它能有效缓解金融时序中普遍存在的噪声敏感、对齐失效与形态失真问题,从而提升聚类结果的市场可解释性与策略鲁棒性。该技术已广泛应用于市场状态识别、行业行为分群、异常交易监测等场景,并成为构建可验证量化分析框架的关键预处理层。本文聚焦A股真实行情数据,详解从原始OHLCV到可聚类时间序列的完整链路,涵盖DTW距离计算、层次聚类 阅读详情

相关推荐

基于Matlab与Bladed联合仿真的交互软件设计

基于Matlab与Bladed的交互软件设计

weixin_45014222的博客 815

LA4080/UVa1416 Warfare And Logistics 最短路树

题目大意: 求图中两两点对最短距离之和 允许你删除一条边,让你最大化删除这个边之后的图中两两点对最短距离之和。 暴力:每次枚举删除哪条边,以每个点为源点做一次最短路,复杂度\(O(NM^2logN)\)。 值得注意的是,\(Dijkstra\)的复杂度\(O(NlogN)\)是关于边而非点的。 这个复杂度对于\(n=100,m=1000\)的数据难以接受。我们考虑对每个点建出其最短路树。容易想...

weixin_33878457的博客 147

ICNN实现入侵检测的思路与源码(CIC-IDS-2017)

基于ICNN实现入侵检测,可用于现实网络

t1274171989的博客 8415

第五十七题 UVa 1416 or LA 4080 Warfare And Logistics

传送门 有、艹蛋 用来复习Dijkstra算法啦 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> using namespace std; const int INF = 0x7...

苦鬼·。 167

瑶芯技术分享 | 三相维也纳PFC功率器件损耗分析

电流的流通路径为:从A相电网正极流出,经过电感La,再经过二极管Da1流到直流侧电容C1,最终通过另外两相回到A相电网,具体流通路径如图2(a)所示。电流的流通路径为:从A相电网正极流出,经过电感La,再经过开关管Sa1和开关管Sa2的反向二极管流到直流侧中点N,最终通过另外两相回到A相电网,具体流通路径如图2(b)所示。通态损耗的产生是由电流正向流经IGBT 或者FRD上产生一定的压降,损耗就是正向电流和器件两端正向压降的乘积,开关损耗和反向恢复损耗则是跟开关过程中的直流电压和开关电流有关。

2301_76606324的博客 5730

告别TI官网迷路!手把手教你用C2000Ware为TMS320F28027搭建Proteus仿真工程模板

本文详细指导如何使用C2000Ware为TMS320F28027搭建Proteus仿真工程模板,帮助DSP开发者快速上手。从资源获取、工程目录设计到关键文件配置,再到CCS与Proteus的联调技巧,全面解析仿真工程搭建的每个步骤,特别适合初学者和工程师参考。

weixin_42715608的博客 472

UVA1416/LA4080 Warfare And Logistics

题目大意:有N个点,M条路,如果两条路不连通的话,就将这两条路的距离设置为L 现在要求你求出每两点之间的最短距离和 接着要求 求出炸断 给出的M条路中的一条路后,每两点之间的最短距离和的最大值(翻译来自http://blog.youkuaiyun.com/l123012013048/article/details/47297393) 单源最短路树:把源点到其他点的最短路拼起来,形...

weixin_30673715的博客 155

20-CUDA规约算法:并行求和优化策略-✨

本文介绍了GPU上高效并行规约(Reduction)算法的优化技巧。规约是将大量数据合并为单个值的基础计算模式,广泛应用于科学计算等领域。文章从基础并行规约实现出发,逐步讲解了三种关键优化策略:1)交错寻址减少共享内存bank冲突;2)循环展开降低分支预测开销;3)多级规约处理大规模数据。性能对比显示,优化策略可带来最高4.5倍的加速效果。最后总结了最佳实践,包括合理使用共享内存、循环展开和warp级优化等技巧。这些优化方法可显著提升GPU计算密集型应用的性能。

2301_79143213的博客 171

UVA1416 Warfare And Logistics(LA4080)

首先用Dijkstra求出每对点距离; 以及每条边是否属于以某个点为单源的树上 然后枚举删除每条边: 之后对于每个单源,如果这条边在上面则重新对这个点dijkstra, 然后修改相应的边; 否则每个点到这个单源的最短距离肯定不变(在原C基础上修改) wrong了整整一天,原来是求与源点相邻的点时忘了会有重边的情况,坑死了…… #include #incl

cx422803902的专栏 874

跨境电商产品信息抓取:使用Python爬虫进行市场分析

跨境电商平台是指为不同国家和地区的买卖双方提供在线交易服务的电子商务平台。亚马逊(Amazon):全球最大的电商平台之一,提供丰富的商品种类和全球配送服务。eBay:全球知名的在线拍卖和购物网站,支持个人和企业卖家。速卖通(AliExpress):阿里巴巴旗下的跨境电商平台,主要面向全球消费者提供中国制造的商品。Wish:以移动端为主的跨境电商平台,主打低价商品和个性化推荐。这些平台上的商品数据包括商品名称、价格、销量、用户评价、库存等信息,对于市场分析具有重要价值。

2201_76125261的博客 1233

PyQt5数据库开发3 6 QSqlQuery完整实操案例【图文详解】

PyQt5数据库开发3 6.1 QSqlQuery实操案例【多图详解】,本文有点长,主要每一个步骤都有对应的图文教程!!!

qq_53317005的博客 2962

【UVA1416】(LA4080) Warfare And Logistics (单源最短路)

题目: Sample Input4 6 10001 3 21 4 42 1 32 3 33 4 14 2 2Sample Output28 38 题意:   给出n个节点m条无向边的图,每条边权都为正。令c等于每对结点的最短路长度之和。要求删一条边后使得新的c值c‘最大。不连通两点的最短路长度视为L。(1<=n<=100,1<=m<=1000,1&...

weixin_30542079的博客 67

model_optimizer将pi05端到端延时进一步优化到68.13ms了

目前在保持灵活性和性能之间找到一个较好的平衡。vit, llm仍然使用onnx->trt_engine的路径,量化可以通过https://github.com/NVIDIA/Model-Optimizer.git支持。同时支持通过cutedsl手写算子进行进一步优化denoise因为步数多,kernel launch多,因此完全通过手写融合算子实现,将所有steps进行一次大的cuda graph capture.

happyAnger6的专栏 59

uva 10917 Walk Through the Forest(最短路+DP路径,4级)

Description Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he lik

nealgavin的专栏 2130

jre9下载 jdk9

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

CF-29C - Mail Stamps(DFS+离散化)

C - Mail Stamps Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 29C Description

nealgavin的专栏 1707

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

hdu 4756 Install Air Conditioning(MST+全边次小树,4级)

Install Air Conditioning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 174    Accepted Submission(s): 23 Problem Description   

nealgavin的专栏 1443

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

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

hdu 4650 Minimum Average Weight Path(最短路,5级)

第4场多校联合训练解题报告——详见杭电ACM微博~ Minimum Average Weight Path Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 94    Accepted Submissio

nealgavin的专栏 1389

HDU 1068 Girls and Boys(二分图最大独立点集,3级)

Girls and Boys Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status   Appoint description:  System Crawler  (2012-10-30) Description the secon

nealgavin的专栏 1229

uva 1364 - Knights of the Round Table(点双连通分量,5级)

Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising tha

nealgavin的专栏 1224

ZOJ 3780 Paint the Grid Again(topsort)

ZOJ Problem Set - 3780 Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black

nealgavin的专栏 1209

10054 - The Necklace(欧拉回路+DFS,2级)

Problem D: The Necklace  My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure belo

nealgavin的专栏 1184

hdu 4725 The Shortest Path in Nya Graph(堆+dij,最短路,5级)

The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 193    Accepted Submission(s): 38 Problem Description Th

nealgavin的专栏 1167

hdu 4685 Prince and Princess(最大匹配+强连通所点,5级)

Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 248    Accepted Submission(s): 76 Problem Description There are n p

nealgavin的专栏 1149

uva 11374 Airport Express(最短路dijistra+堆优化,4级)

Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. The

nealgavin的专栏 1124

uva 1423 - Guess (topsort,4级)

Given a sequence of integers, a1, a2,..., an , we define its sign matrix S such that, for 1ijn , Sij = `` + " if ai +...+ aj > 0 ; Sij = `` - " if ai +...+ aj  ; and Sij = ``0" otherwise. For exa

nealgavin的专栏 1121
上一篇: uva 10917 Walk Through the Forest(最短路+DP路径,4级)
下一篇: windows 建立窗口的程序代码
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值