lightoj 1002 变形dijkstra

本文介绍了一个经典的图论问题——寻找从各个城市到特定城市的最大边最小值路径算法。通过使用邻接矩阵和改进的迪杰斯特拉算法实现,解决了如何找到各节点到目标节点之间的路径成本问题,并给出了具体的代码实现。

I am going to my home. There are many cities and many bi-directional roads between them. The cities are numbered from 0 to n-1 and each road has a cost. There are m roads. You are given the number of my city t where I belong. Now from each city you have to find the minimum cost to go to my city. The cost is defined by the cost of the maximum road you have used to go to my city.

For example, in the above picture, if we want to go from 0 to 4, then we can choose

1) 0 - 1 - 4 which costs 8, as 8 (1 - 4) is the maximum road we used
2) 0 - 2 - 4 which costs 9, as 9 (0 - 2) is the maximum road we used
3) 0 - 3 - 4 which costs 7, as 7 (3 - 4) is the maximum road we used

So, our result is 7, as we can use 0 - 3 - 4.

Input
Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a blank line and two integers n (1 ≤ n ≤ 500) and m (0 ≤ m ≤ 16000). The next m lines, each will contain three integers u, v, w (0 ≤ u, v < n, u ≠ v, 1 ≤ w ≤ 20000) indicating that there is a road between u and v with cost w. Then there will be a single integer t (0 ≤ t < n). There can be multiple roads between two cities.

Output
For each case, print the case number first. Then for all the cities (from 0 to n-1) you have to print the cost. If there is no such path, print ‘Impossible’.

Sample Input
Output for Sample Input
2

5 6
0 1 5
0 1 4
2 1 3
3 0 7
3 4 6
3 1 8
1

5 4
0 1 5
0 1 4
2 1 3
3 4 7
1
Case 1:
4
0
3
7
7
Case 2:
4
0
3
Impossible
Impossible

几乎就是裸题….
用这个熟悉一下最短路

#include<iostream>
#include<cstdio>
#include<cmath>
#include<memory.h>
#include<algorithm>
using namespace std;
int tu[500][500],n,m,dis[500],s;
bool yijing[500];
int inf=0x3f3f3f3f;
int main()
{
    int T;
    cin>>T;
    int u=0;
    while(T--)
    {
        memset(tu,0x3f,sizeof(tu));
        memset(dis,0x3f,sizeof(dis));
        memset(yijing,0,sizeof(yijing));
        cin>>n>>m;
        int l,q,w;
        while(m--)
        {
            cin>>q>>l>>w;
            tu[q][l]=min(tu[q][l],w);
            tu[l][q]=tu[q][l];
        }
        for(int a=0;a<n;a++)tu[a][a]=0;
        cin>>s;
        for(int a=0;a<n;a++)dis[a]=tu[a][s];
        dis[s]=0;
        yijing[s]=1;
        for(int a=0;a<n-1;a++)
        {
            int zuobiao,daxiao=inf;
            for(int b=0;b<n;b++)
            {
                if(dis[b]<daxiao&&yijing[b]==0)
                {
                    zuobiao=b;
                    daxiao=dis[b];
                }
            }
            yijing[zuobiao]=1;
            for(int b=0;b<n;b++)
            {
                if(!yijing[b]&&tu[b][zuobiao]!=inf)
                {
                    dis[b]=min(dis[b],max(dis[zuobiao],tu[zuobiao][b]));
                }
            }
        }
        printf("Case %d:\n",++u);
        for(int a=0;a<n;a++)
        {
            if(dis[a]==inf)
            {
                cout<<"Impossible"<<endl;
                continue;
            }
            cout<<dis[a]<<endl;
        }
    }
    return 0;
}
需求响应动态冰蓄冷系统与需求响应策略的优化研究(Matlab代码实现)内容概要:本文围绕“需求响应动态冰蓄冷系统与需求响应策略的优化研究”展开,基于Matlab代码实现,重点探讨了冰蓄冷系统在电力需求响应背景下的动态建模与优化调度策略。研究结合实际电力负荷与电价信号,构建系统能耗模型,利用优化算法对冰蓄冷系统的运行策略进行求解,旨在降低用电成本、平衡电网负荷,并提升能源利用效率。文中还提及该研究为博士论文复现,涉及系统建模、优化算法应用与仿真验证等关键技术环节,配套提供了完整的Matlab代码资源。; 适合人群:具备一定电力系统、能源管理或优化算法基础,从事科研或工程应用的研究生、高校教师及企业研发人员,尤其适合开展需求响应、综合能源系统优化等相关课题研究的人员。; 使用场景及目标:①复现博士论文中的冰蓄冷系统需求响应优化模型;②学习Matlab在能源系统建模与优化中的具体实现方法;③掌握需求响应策略的设计思路与仿真验证流程,服务于科研项目、论文写作或实际工程方案设计。; 阅读建议:建议结合提供的Matlab代码逐模块分析,重点关注系统建模逻辑与优化算法的实现细节,按文档目录顺序系统学习,并尝试调整参数进行仿真对比,以深入理解不同需求响应策略的效果差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值