博客
关于我
Codeforces Round #617 (Div. 3) F. Berland Beauty(LCA+思维)
阅读量:387 次
发布时间:2019-03-05

本文共 648 字,大约阅读时间需要 2 分钟。

在这里插入图片描述

在这里插入图片描述
题意:给定一棵n个点的树以及n-1条边,现在给出m组ui,vi,wi,表示ui到vi这条最短路径上的最小边权是wi,要你构造出树的边权。
思路:树上两点的最小边权可以通过lca的方法来遍历求出,关键是怎么构造边权?其实可以把给出的m组条件按从大到小排序,只要保证i点和j点的路径上是权值最大的边先赋值就行。

#include
using namespace std;const int maxn=5e3+1;const int INF=1e6;int n,m,num[maxn],size[maxn],ans[maxn],father[maxn],deep[maxn];struct cxk{ int v,id;};struct node{ int u,v,w;}s[maxn];vector
g[maxn];bool cmp(const node &a,const node &b){ return a.w>b.w;}void dfs(int u,int fa){ father[u]=fa; deep[u]=deep[fa]+1; for(auto to:g[u]) { if(to.v==fa) continue; dfs(to.v,u); size[to.v]=to.id; } num[u]=INF;}bool check(int x,int y,int k){ int minn=INF; if(deep[x]

转载地址:http://woewz.baihongyu.com/

你可能感兴趣的文章
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>