第十五周:[Sicily]1504. Slim Span

西汉BC76年世界历史地图矢量文件SHP格式.zip 本资源为《西汉BC76年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.23 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。 立即下载

Description
Given an undirected weighted graph G, you should find one of spanning trees specified as follows.
The graph G is an ordered pair (V, E), where V is a set of vertices {v1, v2, , vn} and E is a set of undirected edges {e1, e2, , em}. Each edge e ? E has its weight w(e).
A spanning tree T is a tree (a connected subgraph without cycles) which connects all the n vertices with n ? 1 edges. The slimness of a spanning tree T is defined as the difference between the largest weight and the smallest weight among the n ? 1 edges of T.
Figure 5: A graph G and the weights of the edges
For example, a graph G in Figure 5(a) has four vertices {v1, v2, v3, v4} and five undirected edges {e1, e2, e3, e4, e5}. The weights of the edges are w(e1) = 3, w(e2) = 5, w(e3) = 6, w(e4) = 6, w(e5) = 7 as shown in Figure 5(b).
Figure 6: Examples of the spanning trees of G
There are several spanning trees for G. Four of them are depicted in Figure 6(a)~(d). The spanning tree Ta in Figure 6(a) has three edges whose weights are 3, 6 and 7. The largest weight is 7 and the smallest weight is 3 so that the slimness of the tree Ta is 4. The slimnesses of spanning trees Tb, Tc and Td shown in Figure 6(b), (c) and (d) are 3, 2 and 1, respectively. You can easily see the slimness of any other spanning tree is greater than or equal to 1, thus the spanning tree Td in Figure 6(d) is one of the slimmest spanning trees whose slimness is 1.
Your job is to write a program that computes the smallest slimness.
Input
The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset has the following format.
n m
a1 b1 w1
?
am bm wm
Every input item in a dataset is a non-negative integer. Items in a line are separated by a space. n is the number of the vertices and m the number of the edges. You can assume 2 ? n ? 100 and 0 ? m ? n(n ? 1)/2. ak and bk (k = 1, , m) are positive integers less than or equal to n, which represent the two vertices vak and vbk connected by the kth edge ek. wk is a positive integer less than or equal to 10000, which indicates the weight of ek. You can assume that the graph G = (V, E) is simple, that is, there are no self-loops (that connect the same vertex) nor parallel edges (that are two or more edges whose both ends are the same two vertices).
Output
For each dataset, if the graph has spanning trees, the smallest slimness among them should be printed. Otherwise, ?1 should be printed. An output should not contain extra characters.
Sample Input
4 5
1 2 3
1 3 5
1 4 6
2 4 6
3 4 7
4 6
1 2 10
1 3 100
1 4 90
2 3 20
2 4 80
3 4 40
2 1
1 2 1
3 0
3 1
1 2 1
3 3
1 2 2
2 3 5
1 3 6
5 10
1 2 110
1 3 120
1 4 130
1 5 120
2 3 110
2 4 120
2 5 130
3 4 120
3 5 110
4 5 120
5 10
1 2 9384
1 3 887
1 4 2778
1 5 6916
2 3 7794
2 4 8336
2 5 5387
3 4 493
3 5 6650
4 5 1422
5 8
1 2 1
2 3 100
3 4 100
4 5 100
1 5 50
2 5 50
3 5 50
4 1 150
0 0
Sample Output

1
20
0
-1
-1
1
0
1686
50


就是求给出的图中,所有生成树中最大权值边与最小权值边的差的最小值。首先将所有边按照权值升序排序,然后从权值最小的边开始用kruskal法求最小生成树,因为以该边开始的最小生成树,得到的最大权值边与最小权值边的差值肯定是以该边开始的生成树里最小的。因此就转换成了以不同边开始求最小生成树的问题。然后继续求以权值第二小的边开始的最小生成树。。。一直求到以权值第m-(n-1)大的边开始的最小生成树(因为最小生成树有(n-1)条边),所有这些最小生成树中求得的最大权值边与最小权值边的差的最小值即为所求。


#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

struct v{
    int start;
    int end;
    int weight;
};

v vs[5000];
int belong_set[101],n,m,INF = 10000;

void update_belong_set(int before,int now){
    for(int i = 1;i <= n;i++)
        if(belong_set[i] == before)
            belong_set[i] = now;
}

int spanning_tree(int min_start_v){
    for(int i = 1;i <= n;i++)
        belong_set[i] = i;
    int cur_v = min_start_v,v_in_tree = 0;
    while(cur_v < m){
        if(belong_set[vs[cur_v].start] != belong_set[vs[cur_v].end]){
            update_belong_set(belong_set[vs[cur_v].end],belong_set[vs[cur_v].start]);
            v_in_tree ++;
            if (v_in_tree == n - 1)
                return vs[cur_v].weight - vs[min_start_v].weight;
        }
        cur_v ++;
    }
    return INF;
}

bool cmp(v v1,v v2){
    return v1.weight < v2.weight;
}

int main(){
    while(cin>>n>>m){
        if(n == 0 && m == 0)
            break;
        int i,cur_min,ans = INF;
        for(i = 0;i < m;i++)
            cin>>vs[i].start>>vs[i].end>>vs[i].weight;
        sort(vs,vs+m,cmp);
        for(i = 0;i <= m -(n - 1);i++){
            cur_min = spanning_tree(i);
            ans = min(cur_min,ans);
        }
        ans == INF ? cout<<"-1"<<endl : cout<<ans<<endl;
    }
    return 0;
}
西汉BC23年世界历史地图矢量文件SHP格式.zip 本资源为《西汉BC23年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.14 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。 立即下载

相关推荐

技术转移机构在拓展企业服务时,最常见的痛点有哪些以及如何解决?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

Sicily 1504. Slim Span

1504. Slim Span Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows.

Nightonke's Blog 539

水下无人航行器UUV三维路径跟踪、LOS+反步优化控制程序、三维螺旋线速度+角度(Matlab代码实现)

内容概要:本文档系统阐述了水下无人航行器(UUV)在三维空间中的路径跟踪控制技术,聚焦于基于视线引导(Line-of-Sight, LOS)与反步法(Backstepping)相结合的优化控制策略的设计与实现,并通过Matlab平台完成三维螺旋线轨迹下的仿真验证。文档详细涵盖了UUV的动力学建模、非线性与强耦合特性分析、控制器设计流程、仿真步骤及结果评估,重点解析了LOS导引律在路径趋近中的应用与反步法在系统稳定性控制中的递归设计机制。此外,资源还整合了滑模控制、模型预测控制(MPC)、自适应神经网络控制等多种先进控制方法在UUV及无人船系统中的应用案例,配套提供完整的Matlab代码与详尽说明文档,支持算法复现与科研拓展。; 适合人群:具备自动控制理论基础和Matlab编程能力,从事海洋工程、智能控制、机器人导航与路径规划等领域的研究生、科研人员及工程技术人员。; 使用场景及目标:① 实现UUV在复杂海洋环境下高精度的三维路径跟踪控制;② 深入理解并掌握LOS导引律与反步法在非线性欠驱动系统中的协同设计与稳定性分析方法;③ 借助提供的仿真代码开展先进控制算法的对比研究与优化设计,支撑学术论文撰写、课题攻关或工程项目开发; 阅读建议:建议结合Matlab代码逐模块剖析,重点关注控制律构建与李雅普诺夫稳定性证明过程,同时对比PID、滑模、MPC等不同控制策略的跟踪性能差异,深入探究其在实际工程系统中的适用边界与优化潜力。

第十周:[Leetcode]486. Predict the Winner

Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a

line02的专栏 497

XGBoost调参新姿势:Bayesian优化实战指南(附完整代码)

本文详细介绍了如何使用Bayesian优化方法高效调优XGBoost模型参数。通过解析Bayesian优化核心原理和XGBoost关键参数,提供完整的实战代码示例,帮助读者掌握这一智能调参技术,显著提升模型性能。文章特别适合机器学习工程师和数据科学家阅读。

weixin_42536058的博客 369

ADS2023实战:2.4GHz超外差接收机从设计到链路预算全流程解析

本文以ADS 2023软件为平台,详细解析了2.4GHz超外差接收机从核心指标定义、架构原理到完整链路搭建与仿真的全流程。通过实战演练,重点阐述了如何利用ADS进行谐波平衡仿真和链路预算分析,以量化评估系统增益、噪声系数等关键性能,为射频工程师提供了一套从理论到仿真的系统级设计方法。

herb5的博客 830

第十六周:[Sicily]1321. Robot

Description Karell Incorporated has designed a new exploration robot that has the ability to explore new terrains, this new robot can move in all kinds of terrain, it only needs more fuel to move in r

line02的专栏 462

告别手动抓信号!Synopsys AXI VIP的Port Monitor实战:5分钟搞定与Scoreboard的TLM连接

本文详细介绍了Synopsys AXI VIP的Port Monitor功能,帮助验证工程师快速实现与Scoreboard的TLM连接,5分钟内完成自动数据收集。通过实战指南和常见问题排查,提升验证效率,告别手动抓信号的繁琐流程。

weixin_30565327的博客 311

第五周:[Leetcode]55. Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you

line02的专栏 423

【gcc】跨版本兼容实战:高版本编译程序在低版本glibc环境下的部署方案

本文针对高版本gcc编译的程序在低版本glibc环境下部署的兼容性问题,提供了四种实战解决方案:静态编译的局限性、容器化部署的优雅方案、使用Devtoolset工具链的官方支持,以及最通用灵活的打包依赖SO发布方案。重点剖析了通过设置RPATH和Interpreter或使用patchelf工具,实现程序与自带库的独立部署,有效解决glibc版本鸿沟。

weixin_29237635的博客 376

四参数与七参数坐标转换含义及区别

一.前言 不同坐标系,其椭球体的长半径,短半径和扁率是不同的。比如我们常用的四种坐标系北京54、西安80、WGS84、CGCS2000所对应的椭球体,它们的椭球体参数就各不相同。而不同空间直角坐标系之间的转换一般通过七参数或者四参数来实现坐标转换。 二.四参数转换 两个不同的二维平面直角坐标系之间转换通常使用四参数模型,四参数适合小范围测区的空间坐标转换,相对于七参数转换的优势在于只需要2个公共已知点就能进行转换,操作简单。 在该模型中有四个未知参数,即: (1)两个坐标平...

尘海折柳的博客 1万+

第八周:[Leetcode]5. Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Exampl

line02的专栏 377

paddle 43 用onnxruntime实现ppyoloe模型的部署(含python和c++版本)

PP-YOLOE+是PP-YOLOE模型的升级版,PP-YOLOE+_l在COCO test-dev2017达到了53.3的mAP, 同时其速度在Tesla V100上达到了78.1 FPS。PP-YOLOE+_s/m/x同样具有卓越的精度速度性价比。paddle官方只给出了基于paddle框架的部署案例,为了更好的部署,为此实现将paddle模型转换为onnx模型,然后在python下实现onnxruntime部署。后续会补充c++ onnxruntime部署

a486259的博客 1924

第七周:[hihocoder]#1050 : 树中的最长路

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅仅可以拼凑成一棵二叉树!还可以拼凑成一棵多叉树——好吧,其实就是更为平常的树而已。 但是不管怎么说,小Ho喜爱的玩具又升级换代了,于是他更加爱不释手(其实说起来小球和木棍有什么好玩的是吧= =)。小Ho手中

line02的专栏 376

YOLO26涨点改进 | 全网独家创新,注意力改进篇 | TGRS 2025 | 引入APCM自适应像素级协同机制,动态增强目标区域、抑制背景噪声,助力YOLO26做红外小目标检测有效涨点

本文提出一种基于APCM模块改进的YOLO26网络模型,通过像素级局部-全局协同建模动态增强目标特征并抑制背景噪声。APCM模块采用轻量化设计,无需复杂参数,在特征提取阶段有效提升目标区域特征表达质量,尤其适用于低对比度和复杂场景下的目标检测。实验表明,该方法能显著提高小目标检测精度和模型鲁棒性,同时保持较低计算开销。模块通过局部特征分支和全局特征分支的协同融合,实现了对红外小目标的有效增强,在NUAA-SIRST和IRSTD-1K数据集上性能优于现有方法。文章还提供了完整的代码实现和配置指南。

Ai缝合怪、助力小伙伴高效发论文 197

Modbus协议学习第一篇之基础概念

因工作需要而接触Modbus,正在恶补知识,利用博客的方式来加深理解和记忆,同时希望同行大佬能一起交流。

hzf978742221的博客 884

第八周:[Leetcode]300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefo

line02的专栏 361

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

第六周:[Leetcode]127. Word Ladder

Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a tim

line02的专栏 352

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

第十七周:[Sicily]机考模拟题1000-1006

1000.函数求值:直接暴力模拟即可。class Solution { public: int F(int k, int n) { int ans[15][15] = {0}; int i,j,kk,cur; for(i = 0;i <= n;i++) ans[0][i] = i; for(i = 1;i <= k;i++)

line02的专栏 351

第五周:[Leetcode]121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), de

line02的专栏 343

第十三周:[Sicily]1423. 魔王bug的2色定理

Description 背景: 传说中魔王bug被杀时留下了一股神秘的力量,但是同时也留下了一个具难的题目,如果你能解答这个 具难的题目,你就能获得bug魔王留下的神秘力量…… 题目描述: 魔王bug的难题来自于它自创的2色定理,魔王bug坚信:天地万物,有阴必有阳,有正必有负,有黑必有白, 有邪恶的魔王必有正义的天使 >_< ….. 魔王bug留下了一幅N个点M个边的图,图中有些点已

line02的专栏 338

第十九周:课后习题8.8

解: 对于任意一个3SAT实例: 若其中某个子句中包含了同一个文字多次,则可以将这些相同的文字合并为一次; 若某个变量同时包含了true和false,则该变量可以去掉。 因此,在每个子句中添加一些没用的辅助变量,这样就可以将每个子句中包含的文字数目扩充到四个。 即将3SAT实例转化成了一个EXACT 4SAT问题。 这就通过将3SAT归约到

line02的专栏 337

第一周:[LeetCode]1. Two Sum

[LeetCode]1. Two Sum

line02的专栏 325

第四周:[LeetCode]332. Reconstruct Itinerary

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the

line02的专栏 310

第十八周:[Leetcode]98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The r

line02的专栏 303

第十四周:[LeetCode]10. Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string

line02的专栏 301
上一篇: 第十四周:[LeetCode]10. Regular Expression Matching
下一篇: 第十六周:[Sicily]1321. Robot
line02
博客等级 码龄15年 3粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值