HDU 4725 The Shortest Path in Nya Graph (最短路拆点建图)

Palantir 凭什么两年涨 20 倍?深度解析解决 AI 幻觉的 “本体论“ 核心原理 本文深度解析了Palantir本体(Ontology)的核心原理及其在企业AI应用中的革命性价值。本体通过构建结构化的语义层与动态执行层,将企业分散的数字资产(数据集、虚拟表、模型)映射为现实世界的数字孪生,使大模型能够在**严格的业务规则与数据边界内**进行推理与决策,从而从架构层面彻底解决AI幻觉问题。这一技术架构不仅帮助Palantir实现股价两年增长20倍、市值突破4000亿美金的商业成功,更成为SAP、Salesforce等ERP巨头争相模仿的下一代企业智能标准范式。通过航空业飞机故障应急处理等实 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=4725

Problem Description
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.
The Nya graph is an undirected graph with “layers”. Each node in the graph belongs to a layer, there are N nodes in total.
You can move from any node in layer x to any node in layer x + 1, with cost C, since the roads are bi-directional, moving from layer x + 1 to layer x is also allowed with the same cost.
Besides, there are M extra edges, each connecting a pair of node u and v, with cost w.
Help us calculate the shortest path from node 1 to node N.

Input
The first line has a number T (T <= 20) , indicating the number of test cases.
For each test case, first line has three numbers N, M (0 <= N, M <= 105) and C(1 <= C <= 103), which is the number of nodes, the number of extra edges and cost of moving between adjacent layers.
The second line has N numbers li (1 <= li <= N), which is the layer of ith node belong to.
Then come N lines each with 3 numbers, u, v (1 <= u, v < =N, u <> v) and w (1 <= w <= 104), which means there is an extra edge, connecting a pair of node u and v, with cost w.

Output
For test case X, output “Case #X: ” first, then output the minimum cost moving from node 1 to node N.
If there are no solutions, output -1.

Sample Input

2
3 3 3
1 3 2
1 2 1
2 3 1
1 3 3

3 3 3
1 3 2
1 2 2
2 3 2
1 3 4

Sample Output

Case #1: 2
Case #2: 3


最短路。

主要是建图。

N个点,然后有N层,要假如2*N个点。

总共是3*N个点。

点1~N就是对应的实际的点1~N. 要求的就是1到N的最短路。

然后点N+1 ~ 3*N 是N层拆出出来的点。

到第i层的入边是点N+2*i-1, 出边从点N+2*i 出来。(1<= i <= N)

N + 2*i 到 N + 2*(i+1)-1 加边长度为C. 表示从第i层到第i+1层。

N + 2*(i+1) 到 N + 2*i - 1 加边长度为C,表示第i+1层到第i层。

如果点i属于第u层,那么加边 N + 2*u -1 -> i i-> N + 2*u 长度都为0

然后用优先队列优化的Dijkstra就可以搞出最短路了

保证边建对。。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

const int N = 1e5 + 100;
const int MAXN = 3*N;
const int INF = 0x3f3f3f3f;
struct Edge
{
    int v,w;
    Edge(int v,int w):v(v),w(w){}
};
vector<Edge> E[MAXN]; int dis[MAXN]; bool vis[MAXN];
void add(int u,int v,int w)
{
    E[u].push_back(Edge(v,w));
};
struct Node
{
    int v,w;
    Node(){}
    Node(int v,int w):v(v),w(w){}
    friend bool operator < (const Node &a,const Node &b)
    {
        return a.w > b.w;
    }
};
int dijstra(int n)
{
    for(int i=1;i<=3*n;i++) dis[i] = INF;
    memset(vis,false,sizeof(vis));
    priority_queue<Node>que;
    que.push(Node(1,0));
    dis[1] = 0;
    while(!que.empty())
    {
        Node now = que.top();
        que.pop();

        int u = now.v;
        if(vis[u]) continue;
        vis[u] = true;

        for(int i=0;i<E[u].size();i++)
        {
            int v = E[u][i].v;
            int c = E[u][i].w;
            if(!vis[v] && dis[v] > dis[u] + c)
            {
                dis[v] = dis[u] + c;
                que.push(Node(v,dis[v]));
            }
        }
    }
    if(dis[n] == INF) dis[n] = -1;
    return dis[n];
}
int main()
{
    int T;
    scanf("%d",&T);
    for(int cas = 1; cas<=T ;cas++)
    {
        int n,m,c;
        scanf("%d%d%d",&n,&m,&c);
        for(int i=1;i<=3*n;i++) E[i].clear();
        for(int i=1;i<=n;i++)
        {
            int x; scanf("%d",&x);
            add(n+2*x-1,i,0);
            add(i,n+2*x,0);
        }
        for(int i=1;i<n;i++)
        {
            add( n+2*(i+1),n+2*i-1,c);
            add( n+2*i,n+2*(i+1)-1,c);
        }
        while(m--)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            add(u,v,w);
            add(v,u,w);
        }
        printf("Case #%d: %d\n",cas,dijstra(n));
    }
    return 0;
}
基于CutLSTM-ATT 模型的刀具磨损预测-【一个月之内发一篇中文核心辅导】 阅读详情

相关推荐

Unity中URP下的菲涅尔效果实现(个性化修改)

在上篇文章中,我们实现了 URP 下的菲涅尔基础效果,我们在这篇文章中,对其进行自定义化修改。

楠溪泽岸的博客 2067

HDU - 4725The Shortest Path in Nya Graph

This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just m

dreambyday 318

基于STM32与FPGA Cyclone IV的FSMC高速数据通信实战解析

本文详细解析了基于STM32的FSMC接口与FPGA Cyclone IV实现高速并行数据通信的实战方案。通过将FPGA模拟为SRAM设备,构建了MCU与FPGA之间的高速数据通道,并深入探讨了硬件连接、STM32软件配置、FPGA逻辑设计及性能优化等关键步骤,为图像处理、高速采集等需要大数据量交换的嵌入式应用提供了稳定高效的通信解决方案。

swift5iosmith的博客 307

[kuangbin]专题四 最短路练习 The Shortest Path in Nya Graph HDU - 4725【dijkstra】

【题目描述】 This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph...

inv0ker的博客 254

STM32L051低功耗模式下LPUART的使用

STM32L0系列低功耗UART配置代码清单及注释,大家可参考学习使用。

嵌入式工程师 2116

保姆级教程:在LKD3588开发板上为RK3588添加SC2210摄像头驱动(含完整DTS配置)

本文提供了一份详细的教程,指导如何在LKD3588开发板上为RK3588处理器添加SC2210摄像头驱动,包括完整的DTS配置和内核编译步骤。教程涵盖了环境准备、驱动文件添加、DTS配置详解、内核编译与烧录、驱动测试以及常见问题排查,帮助开发者快速实现SC2210传感器在RK3588平台上的集成与优化。

weixin_42641741的博客 492

HDU - 4725 The Shortest Path in Nya Graph(增点建图)(图文详解)(超易理解)

The Shortest Path in Nya Graph HDU - 4725增点建图 Dijkstra 邻接表 problem This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco ...

四季不败的博客 586

直流无刷减速电机选型指南:从KV值到霍尔传感器,新手必看的5个关键参数

本文详细解析直流无刷减速电机选型的5个关键参数,包括KV值、转矩、电流与功率、减速比选择以及霍尔传感器配置。通过实战案例和避坑策略,帮助工程师精准匹配电机性能与负载需求,提升工业自动化设备的可靠性和效率。特别强调霍尔传感器在精准控制中的关键作用。

alice7model的博客 632

ACM最短路--The Shortest Path in Nya Graph --SPFA

ACM最短路--The Shortest Path in Nya Graph --SPFA This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do...

weixin_43918046的博客 294

YOLOv8改进 | 主干网络 | 将主干网络替换为轻量化的ShuffleNetv2【原理 + 完整代码】

yolov8,yolov8创新,yolov8改进

kay_545 2573

用生成式AI自动生成测试用例的完整教程

本文旨在帮助测试工程师、开发人员快速掌握“生成式AI自动生成测试用例”的核心技术,覆盖从概念理解、工具选择到实战落地的全流程。无论是Web应用、API接口还是移动端功能测试,你都能找到可复用的方法。本文将按照“概念→原理→实战→避坑”的逻辑展开:先通过生活案例理解生成式AI如何生成测试用例,再拆解核心算法原理,接着用Python代码演示完整生成流程,最后分享实际应用中的优化技巧和未来趋势。生成式AI:能“创造内容”的AI模型(如ChatGPT、CodeLlama),像会写作文的智能笔。测试用例。

AIGC应用创新大全的博客 1592

hdu4725 The Shortest Path in Nya Graph

/** HDU - 4725 The Shortest Path in Nya Graph n个点 m条边 相邻层之间移动的代价为W 接下来n个数代表了第i个点属于哪层 m条边 u-&amp;amp;gt;v w 层的性质 如果相邻的层都存在节点,则lev[i]层的任意节点都能与lev[i]+1的任意节点 以代价 W 相连,同样可以与lev[i]-1的任意节点相连 但若lev[i]层没有节点,那...

Hi_puppy 224

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu4725 The Shortest Path in Nya Graph(最短路:建图拆点技巧)

题意:有n个点,每个点处于一个层次中,相邻层的点可以花费c相互到达,然后还有m条小路。问你从1到n的最短路。 思路:裸的最短路?题意是裸的,但如果你枚举层朴素检点的话。n^2,我一开使没注意n的范围,结果T到怀疑人生。看dalao们的做法是拆点,需要注意的是题目没说同一层的点可以相互到达,所以别让主观意识影响你的判断,还要注意拆完点后不能使得同一层的点相互到达。 大致有两种 1、把每一个点拆...

一身清贫怎敢入繁华 425

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

【HDU - 4725】The Shortest Path in Nya Graph (最短路 虚拟节点)

HDU - 4725 Time Limit: 2000/1000 MS (Java/Others) &nbsp; &nbsp; &nbsp; Memory Limit: 32768/32768 K (Java/Others) 题目描述 This is a very easy problem, your task is just calculate el camino mas corto en u...

Winsoul Blog 1万+

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU - 4725 The Shortest Path in Nya Graph 最短路,思维建图

题目链接 HDU-4725 题意 给定n个点m个带权双向道路,这n个点各自有一个叫层级的属性。相邻层级间的点可以通过花费c转移。求1-n最短路。 思路 这题可能是kuangbin这个专题里难度数一数二的了。思路很清晰,裸的最短路,难点在于建图。这个建图又和POJ - 2502里专门恶心人的建图不一样,是真的需要动脑子的。 关于层级,虽然层级范围是1-n,但没有告诉你一定是1-n全出现,也没有告诉你一个层级只有一个点。这意味着: 离线处理变得困难 只能连接相邻的两层,比如不加处理直接连接1-3层级,如果2层

TheSunspot的博客 798

【详解】The Shortest Path in Nya Graph HDU - 4725 ⭐⭐⭐⭐ 【层级加点建图】

The Shortest Path in Nya Graph HDU - 4725 This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not ...

Suprit's blog 1197

HDU-4725-The Shortest Path in Nya Graph(拆点,最短路)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:给出n个点,这n个点分布在不同的高度上,花费C,可以跳转到相邻的两层之间的任意一个点。给出m条边,这是额外的可行道路。问从1~n的最短路是多少,没有最短路输出-1,本层之间没有道路的话,是不可以跳转的。 思路:核心是拆点,把一个点拆成两个,然后跑一边最短路,拆点结果如图: 哎。。...

永远鲜红の幼月的博客 298

HDU 4725 The Shortest Path in Nya Graph 【dijkstra+堆+分层建图】

HDU 4725 The Shortest Path in Nya Graph 题目链接:vjudge传送门 题目大意: 给定n个点(编号1到n),以及每个点处于的层数(1到n),一个点有一条边通向上/下相邻层的所有点的边,权值为c,另外有额外m条边,记录n个点中任意两点之间带权的边,问从1点出发到n点的最短距离。 具体思路: 处于相邻层的不同层上的点都有一条权值为c的双向边,因此可以每两层中的各...

指弹键盘哼民谣 662

hdu4725The Shortest Path in Nya Graph(拆点 + 最短路dijkstra | SPFA)

题目请戳这里 题目大意:给n个点,m条无向边,边权w,为走这条路的代价。每个点属于某一层,从某层到隔壁层代价都是固定的c,求1到n最短路。 题目分析:最短路。比赛的时候硬上SPFA,结果T出翔了。还是太年轻了啊。 因为每个点可以借助层的属性,到达其他点就有了其他的路径。所以有必要把每层也抽象出额外的点。因为每层的点也是不连通的,就是说如果点i和点j在同一层,并不代表他们之间距离就是0。所以对

ophunter的专栏 1848

【HDU - 4725 The Shortest Path in Nya Graph】【最短路建图】【拆层】【好题】

http://acm.hdu.edu.cn/showproblem.php?pid=4725 【题意】 给你n个点,每个点有一个层的位置 有m条边,连接两点,并且相邻层之间可以通过c来到达 【思路】 将每个层拆出来作为一个点建图 点与点:原来的m条边建双向边 层与层:相邻层建c的双向边 点与层:层到层上的点的距离为0,点到相邻层代表的点为c 注意:相同层上的点的距离不为0 【代...

running_acmer的博客 354

HDU - 4725 The Shortest Path in Nya Graph (技巧建图)

The Shortest Path in Nya Graph This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand...

Error Man 的博客 378

hdu4725 The Shortest Path in Nya Graph (层节点建图+最短路)

问题描述 这是一个非常简单的问题,你的任务是计算el camino mas corto en un grafico,然后单独计算cambiar un poco el algoritmo。如果你对这段话一个字都不懂,那就继续读下去。 Nya图是一个具有“层”的无向图。图中的每个节点都属于一个层,总共有N个节点。 你可以从x层的任意节点移动到x + 1层的任意节点,花费C,因为道路是双向的,所以从x ...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 358

HDU4725 The Shortest Path in Nya Graph 最短路分层

一、内容 This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph,...

Tizzi的博客 964

HDU 4725 The Shortest Path in Nya Graph(最短路拆点)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:n个点,某个点属于某一层。共有n层。第i层的点到第i+1层的点和到第i-1层的点的代价均是C。另外有一类边连接两个点u、v,代价w。求1到n的最短路。 思路:拆点。n个点不动,编号1到n。将n层每层拆成两个点,第i层拆成n+i*2-1,n+i*2。相邻的层连边(n+i*2-1,n+(i...

weixin_33690367的博客 97

HDU4725 - The Shortest Path in Nya Graph (Dijstra + 建图)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725题目大意:现在有N个节点,编号从1到N。有M条权值为Ci无向边,链接着两个节点。 新加入了一个条件,每个节点在一个层内,假设在 x 层,那么在 x 层内的节点可以直接到达 x + 1 层或 x -1 层的任意节点,花费为 C 。现在求从 1 到 N 的最短路。解题过程:比赛的时候没做出来,现在才

ACM_Fish的博客 752

hdu4725 The Shortest Path in Nya Graph

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目意思:有n个层n个点,每个点只属于一个层,一个层可以有多个点(这点很坑)。点通往相邻的层上的点有代价c。有额外m条带权无向路,求点1到点n的最短路。 思路:主要是建图,建完图用spfa/dijkstra跑一边就是了。开始我用vector存每层的信息,相邻层的点相连,最后超...

agyohust791263的博客 117
上一篇: HDU 4366 Successor(dfn序 + 线段树)
下一篇: AC自动机入门题(HDU 2222 + HDU 2896)
WANSNIM
博客等级 码龄12年 27粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址