Network

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1293    Accepted Submission(s): 575

Problem Description
The
ALPC company is now working on his own network system, which is
connecting all N ALPC department. To economize on spending, the backbone
network has only one router for each department, and N-1 optical fiber
in total to connect all routers.
The usual way to measure connecting
speed is lag, or network latency, referring the time taken for a sent
packet of data to be received at the other end.
Now the network is on
trial, and new photonic crystal fibers designed by ALPC42 is trying
out, the lag on fibers can be ignored. That means, lag happened when
message transport through the router. ALPC42 is trying to change routers
to make the network faster, now he want to know that, which router, in
any exactly time, between any pair of nodes, the K-th high latency is.
He needs your help.
 
Input
There are only one test case in input file.
Your
program is able to get the information of N routers and N-1 fiber
connections from input, and Q questions for two condition: 1. For some
reason, the latency of one router changed. 2. Querying the K-th longest
lag router between two routers.
For each data case, two integers N and Q for first line. 0<=N<=80000, 0<=Q<=30000.
Then n integers in second line refer to the latency of each router in the very beginning.
Then N-1 lines followed, contains two integers x and y for each, telling there is a fiber connect router x and router y.
Then
q lines followed to describe questions, three numbers k, a, b for each
line. If k=0, Telling the latency of router a, Ta changed to b; if
k>0, asking the latency of the k-th longest lag router between a and b
(include router a and b). 0<=b<100000000.
A blank line follows after each case.
 
Output
For
each question k>0, print a line to answer the latency time. Once
there are less than k routers in the way, print "invalid request!"
instead.
 
Sample Input
5 5
5 1 2 3 4
3 1
2 1
4 3
5 3
2 4 5
0 1 2
2 2 3
2 1 4
3 3 5
 
Sample Output
3
2
2
invalid request!
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3071 3070 3072 3073 3074 
 
 
找树上两个点路径上的第k大节点
根据lca分别从起点和终点网上找点权,记下来,排序
lca预处理nlogn  lca查询logn  找路径 logn(n个节点的树最多logn层) 排序logn * logn
因此总复杂度(m + n)log^2n
不会超时
 
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
inline void read(int &x){char ch = getchar();char c = ch;x = 0;while(ch < '0' || ch > '9')c = ch, ch = getchar();while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();if(c == '-')x = -x;}
inline void swap(int &a, int &b){int tmp = a;a = b;b = tmp;} const int MAXN = 80000 + 10; struct Edge{int u,v,next;}edge[MAXN << 1];
int head[MAXN],cnt,n,m,w[MAXN],p[20][MAXN],deep[MAXN],fa[MAXN],num[MAXN],b[MAXN];
inline void insert(int a,int b){edge[++cnt] = Edge{a, b, head[a]},head[a] = cnt;} int llog2[MAXN],pow2[30]; void dfs(int u)
{
for(int pos = head[u];pos;pos = edge[pos].next)
{
int v = edge[pos].v;
if(b[v])continue;
b[v] = true,deep[v] = deep[u] + 1,p[0][v] = u,fa[v] = u,dfs(v);
}
} inline void yuchuli()
{
b[1] = true,deep[1] = 0,dfs(1);
register int i;
for(i = 1;i <= llog2[n];i ++)
for(int j = n;j >= 1;j --)
p[i][j] = p[i - 1][p[i - 1][j]];
} inline int lca(int va, int vb)
{
register int i;
if(deep[va] < deep[vb])swap(va, vb);
for(i = llog2[n];i >= 0;i --)
if(deep[va] - pow2[i] >= deep[vb])
va = p[i][va];
if(va == vb)return va;
for(i = llog2[n];i >= 0;i --)
if(p[i][va] != p[i][vb])
va = p[i][va],vb = p[i][vb];
return p[0][va];
} int ans[MAXN],rank; inline void work(int s, int t, int k)
{
int anc = lca(s, t);
int now = s;
register int i = 1;
num[i] = w[now];
while(now != anc)
num[++i] = w[(now = fa[now])];
now = t;
while(now != anc)
num[++i] = w[now], now = fa[now];
std::sort(num + 1, num + 1 + i);
if(i >= k)
ans[++rank] = num[i - k + 1];
else rank++;
} int main()
{
register int i,tmp1,tmp2,tmp3;
llog2[0] = -1,pow2[0] = 1;
for(int i = 1;i <= MAXN;i ++)llog2[i] = llog2[i >> 1] + 1;
for(int i = 1;i <= 25; i++)pow2[i] = (pow2[i - 1] << 1);
read(n),read(m);
for(i = 1;i <= n;i ++)read(w[i]);
for(i = 1;i < n;i ++)read(tmp1),read(tmp2),insert(tmp1, tmp2),insert(tmp2, tmp1);
yuchuli();
for(i = 1;i <= m;i ++)
{
read(tmp1),read(tmp2),read(tmp3);
if(tmp1)work(tmp2, tmp3, tmp1);
else w[tmp2] = tmp3;
}
for(int i = 1;i < rank;i ++)
if(ans[i])
printf("%d\n", ans[i]);
else
printf("invalid request!\n");
if(ans[rank])
printf("%d\n", ans[rank]);
else
printf("invalid request!\n");
return 0;
}

HDU3078 Network [2016年6月计划 树上问题05]的更多相关文章

  1. 洛谷P2912 [USACO08OCT]牧场散步Pasture Walking [2017年7月计划 树上问题 01]

    P2912 [USACO08OCT]牧场散步Pasture Walking 题目描述 The N cows (2 <= N <= 1,000) conveniently numbered ...

  2. ZOJ3195 Design the city [2017年6月计划 树上问题04]

    Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...

  3. HDU3887 Counting Offspring [2017年6月计划 树上问题03]

    Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]

    [POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...

  5. 2016年12月31日 星期六 --出埃及记 Exodus 21:26

    2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...

  6. 2016年12月30日 星期五 --出埃及记 Exodus 21:25

    2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...

  7. 2016年12月29日 星期四 --出埃及记 Exodus 21:24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

  8. 2016年12月28日 星期三 --出埃及记 Exodus 21:23

    2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...

  9. 2016年12月27日 星期二 --出埃及记 Exodus 21:22

    2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...

随机推荐

  1. (转)第01节:初识简单而且强大的Fabric.js库

    Fabric.js是一个功能强大和简单Javascript HTML5的canvas库.Fabric提供了很多可以互动的Canvas元素,还在canvas上提供了SVG的语法分析器. 你可以轻松的使用 ...

  2. 隐藏/显示jeecg-boot 后端管理页面的右侧的系统设置

    登录后台,通过添加一个下拉选项[系统设置]来控制系统的后侧系统设置,布局如下: 修改UserMenu.vue文件 1.全局搜索“账户设置”,找到对应的vue文件:UserMenu.vue 2.添加[系 ...

  3. PAT甲级——A1077 Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  4. 政务私有云盘系统建设的工具 – Mobox私有云盘

    序言 这几年,智慧政务已经成为了政府行业IT建设发展的重要进程.传统办公方式信息传递速度慢.共享程度低.查询利用难,早已成为政府机关获取和利用信息的严重制约因素.建立文档分享共用机制,加强数据整合,避 ...

  5. Django项目:CRM(客户关系管理系统)--83--73PerfectCRM实现CRM模板统一

    {#king_index.html#} {## ————————73PerfectCRM实现CRM模板统一————————#} {% extends "master/sample.html& ...

  6. LL(1),LR(0),SLR(1),LALR(1),LR(1)对比与分析

    前言:考虑到这几种文法如果把具体内容讲下来肯定篇幅太长,而且繁多的符号对初学者肯定是极不友好的,而且我相信看这篇博客的人已经对这几个文法已经有所了解了,本篇博客的内容只是对 这几个文法做一下对比,加深 ...

  7. XAMPP:继MAMP之后,Mac OS X平台下又一款帮你快速搭建服务器环境软件

    之前,有很多人都有打算在自己的Mac OS下搭建一个本地测试用的Apache+PHP+MySQL网络服务器环境. 在目前而言至少有3种办法可以实现这一点: 通过Xcode开发者套件和php.Apach ...

  8. linux 编译C语言代码后产生OBJ文件的方法

    如果你不指定编译成什么文件,gcc默认一步到位,直接生成可执行文件你可以试试以下几个参数 -c 只激活预处理,编译,和汇编,也就是他只把程序做成obj文件 例子用法: gcc -c hello.c 他 ...

  9. OSGi.NET使用笔记

    一手资料来源于“开放工厂”,以下程序将会引用到一个核心文件UIShell.OSGi.dll 目前我对于OSGi这个框架的理解就是,主程序搜索并加载插件,以插件方式开放,便于扩展. 现在开始正式的旅程. ...

  10. 基于Skyline与ArcGIS Server的二三维联动功能实现

    基于Skyline与ArcGIS Server的二三维联动功能实现主要利用WEB技术.ArcGIS for JavaScript.Skyline 二次开发以及ArcGIS 10.1 桌面工具. 利用A ...