21668_WestwardJourneyOnline

2022-5-16 18:20| 发布者: Hocassian| 查看: 27| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505743988700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21668

Title

Westward Journey Online

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21668

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    "Westward Journey" is one of the most popular online games in China, which is developed and run by NIE. The game is based on the famous and romantic Chinese classical fiction "Journey to the West", and the well-know film by Stephen Chow. The story behind "Westward Journey" is fantasy and thus attracts many players.

    The game contains many regions, and different regions are ruled by different dominators. One of the regions which named "Tree World" is now ruled by a monster. There are N castles in this region, and each of them has its importance value (a positive integer not larger than 108). The castles are connected by (N - 1) bidirectional roads. The roads make all the castles connected (that means you can travel between any two castles of them). The importance values of the castles are variable. Now, the monster wants to know something if he destroys one of the roads. In detail, you are to handle totally Q instructions: each of them can be one of the following forms.

    CHANGE  i  wThe importance value of the i-th castle was changed to w ( 1 ≤ w ≤ 108 )
    QUERY  jOutput  min1 × max1 + min2 × max2
    Explanations: The j-th road can divide the "Tree World" into two connected components, named part1 and part2. Here,
    min1: the minimum importance value in part1 ;
    max1: the maximum importance value in part1 ;

    min2: the minimum importance value in part2 ;

    max2: the maximum importance value in part2

    输入

    The first line contains an integer T ( T ≤ 10 ), the number of test cases.

    For each test case, the first line contains two integers N ( 2 ≤ N ≤ 100000 ) and Q ( 1 ≤ Q ≤ 100000 ), indicating the number of castles and instructions.

    The following line contains N integers (positive integer not larger than 108), indicating the initial importance value of each castle (castles are numbered from 1 to N).

    The following (N-1) lines each contains two integers u and v, indicating castle u and castle v are connected directly by a bidirectional road (the roads are numbered from 1 to N-1).

    The following Q lines each contains an instruction according to the specification above.

    输出

    Description

    "Westward Journey" is one of the most popular online games in China, which is developed and run by NIE. The game is based on the famous and romantic Chinese classical fiction "Journey to the West", and the well-know film by Stephen Chow. The story behind "Westward Journey" is fantasy and thus attracts many players.

    The game contains many regions, and different regions are ruled by different dominators. One of the regions which named "Tree World" is now ruled by a monster. There are N castles in this region, and each of them has its importance value (a positive integer not larger than 108). The castles are connected by (N - 1) bidirectional roads. The roads make all the castles connected (that means you can travel between any two castles of them). The importance values of the castles are variable. Now, the monster wants to know something if he destroys one of the roads. In detail, you are to handle totally Q instructions: each of them can be one of the following forms.

    CHANGE  i  wThe importance value of the i-th castle was changed to w ( 1 ≤ w ≤ 108 )
    QUERY  jOutput  min1 × max1 + min2 × max2
    Explanations: The j-th road can divide the "Tree World" into two connected components, named part1 and part2. Here,
    min1: the minimum importance value in part1 ;
    max1: the maximum importance value in part1 ;

    min2: the minimum importance value in part2 ;

    max2: the maximum importance value in part2

    Input

    The first line contains an integer T ( T ≤ 10 ), the number of test cases.

    For each test case, the first line contains two integers N ( 2 ≤ N ≤ 100000 ) and Q ( 1 ≤ Q ≤ 100000 ), indicating the number of castles and instructions.

    The following line contains N integers (positive integer not larger than 108), indicating the initial importance value of each castle (castles are numbered from 1 to N).

    The following (N-1) lines each contains two integers u and v, indicating castle u and castle v are connected directly by a bidirectional road (the roads are numbered from 1 to N-1).

    The following Q lines each contains an instruction according to the specification above.

    Output

    For each "QUERY" instruction, output the result on a separate line.

    Sample Input

    1
    5 3
    1 2 3 4 5
    1 2
    2 3
    3 4
    4 5
    QUERY 1
    CHANGE 1 10
    QUERY 1

    Sample Output

    11
    110

    Source

    样例输入

    1
    5 3
    1 2 3 4 5
    1 2
    2 3
    3 4
    4 5
    QUERY 1
    CHANGE 1 10
    QUERY 1

    样例输出

    11
    110

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部