编程介的小学生 2017-12-04 04:23 采纳率: 20.5%
浏览 790
已采纳

A pungent problem

Problem Description
One day, a couple of friends J and F were playing the game called “RiskCraft”. But J was so confused by what F told him that F almost wanted to bully him. At that time, the occurrence of cheat had exactly prevented J from being mistreated any longer.
Now it's the time for F to make the strategy. There are several forts on the map, and each of the two forts has only one route to connect them. What's more, F had been doing something quiet beyond the expectation. He just got each of the forts armed with a large amount of soldiers. But it seemed apparently that F knew J was cheating. So, F determined to alter the proportion of the army. J was definitely getting really misleading By F's distorted strategies. So, he was really anxious of seeking the help of you.
Please number the forts from 1 to n. For instance, the fort ith number of solider is w(i) ( ps. w(i) may be a negative number as F likes. How rediculous!!), there are several tips of instructions that J hope s could help you work out this dilemma problem.
1. CHANGE u t: this means that F has the intention that he really want to change present group of the soldiers in fort u to t.
2. QMAX u v : this actually indicates that J is curious about what is the max number of the soldiers of a certain forts on the way from u to v.
3. QSUM u v : this absolutely expressed that J furiously have the temptation to know the whole number of the army from fort u to fort v.

Input
There are several test cases.
In each test case, the first line is a positive integer n (1 <=n<=30000) means the number of fort.
The next n-1 lines include two numbers a, b (1<=a, b<=n) indicating there is a path between fort a and fort b.
The next line has n numbers, the i th number w(i) (-30000<=w(i)<=30000) means the amount of the army in fort i.
The following lines has a unique number q (0<=q<=200000), means the total operations in this test case.
Above all, q lines will be definitely displayed on screen, each line offers a string like 'CHANGE u t', 'QMAX u v' or 'QSUM u v'.

Output
For each string 'QMAX' or 'QSUM', give a number express the result of this request.

Sample Input
4
1 2
2 3
4 1
4 2 1 3
12
QMAX 3 4
QMAX 3 3
QMAX 3 2
QMAX 2 3
QSUM 3 4
QSUM 2 1
CHANGE 1 5
QMAX 3 4
CHANGE 3 6
QMAX 3 4
QMAX 2 4
QSUM 3 4

Sample Output
4
1
2
2
10
6
5
6
5
16

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-12-09 15:29
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题