luogu#P4114. Qtree1

Qtree1

Background

The constraints differ from those on SPOJ.

Problem Description

Given a tree with nn nodes, there are two operations:

  • CHANGE i t set the weight of the ii-th edge to tt.
  • QUERY a b output the maximum edge weight on the path from aa to bb. When a=ba = b, output 00.

Input Format

The first line contains an integer nn, the number of nodes. Lines 22 through nn each contain three integers u,v,wu, v, w, indicating that there is an edge between uu and vv with weight ww. Starting from line n+1n + 1, there are an unspecified number of lines. Each line starts with a string, which can be one of:

  • CHANGE followed by two integers x,tx, t, indicating an update operation.
  • QUERY followed by two positive integers a,ba, b, indicating a query operation.
  • DONE indicating the end of input.

Output Format

For each QUERY operation, output one line with a single number: the maximum edge weight on the path between aa and bb.

3
1 2 1
2 3 2
QUERY 1 2
CHANGE 1 3
QUERY 1 2
DONE
1
3

Hint

Constraints

For all test points, it is guaranteed that:

  • 1n1051 \leq n \leq 10^5.
  • 1u,v,a,bn1 \leq u, v, a, b \leq n, 1x<n1 \leq x < n.
  • 1w,t23111 \leq w, t \leq 2^{31} - 1.
  • The number of operations does not exceed 3×1053 \times 10^5.

Translated by ChatGPT 5