HDU3078 Network [June 2016 plan tree issue 05]

Source: Internet
Author: User

Network

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1293 Accepted Submission (s): 575


Problem DescriptionThe ALPC Company are now working on his own network system, which are connecting all N ALPC department. To economize on spending, the backbone network have only one router for each department, and N-1 Optical fiber Connect all routers.
The usual-measure connecting speed is lags, or network latency, referring the time taken for a sent packet of data T O is received at the other end.
Now the network are on trial, and new photonic crystal fibers designed by ALPC42 are trying out, the lag in fibers can be IG Nored. That's 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, which router, in any exactly time , between any pair of nodes, the k-th high latency is. He needs your help.

Inputthere is only one test case in input file.
Your program was able to get the information of N routers and N-1 fiber connections from input, and Q questions for both con Dition:1. For some reason, the latency of one router changed. 2. Querying the k-th longest lag router between.
For the data case, the integers N and Q for first line. 0<=n<=80000, 0<=q<=30000.
then n integers on second line refer to the latency of each router in the very beginning.
Then N-1 lines followed, contains the 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 through each case.

Outputfor each question k>0, print a line to answer the latency time. Once there is less than K routers in the "the", print "Invalid request!" instead.

Sample INPUT5 55 1 2 3 43 12 14 35 32 4 50 1 22 2 32 1 43 3 5

Sample Output322invalid request!

Source multi-university Training Contest 17-host by Nudt

Recommendlcy | We have carefully selected several similar problems for you:3071 3070 3072 3073 3074 find the K-node on the two-point path on the tree based on the LCA to find the right from the starting point and the net point , jot down, sort LCA pretreatment nlogn LCA Query Logn find path Logn (n nodes tree up to Logn layer) sort Logn * Logn therefore total complexity (M + N) log^2n does not time out
#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, c h = GetChar (); while (Ch <= ' 9 ' && ch >= ' 0 ') x = x * + 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];p os;pos = edge[pos].next) {int v = edge[pos].v;if (B[v]) cont INUE;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 (DE EP[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 <=; 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]); elseprintf ("Invalid request!\n"); if (Ans[rank]) printf ("%d\n", Ans[rank]); elseprintf ("Invalid request!\n"); return 0;}

HDU3078 Network [June 2016 plan tree issue 05]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.