1506 : 图神的树
时间限制Time Limit
2
秒Sec
内存限制Memory Limit
1024
兆MB
提交次数Submitted
0 次Times
通过次数Solved
0 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
给你一棵有 n 个节点的带权无向树(节点编号 1\ldots n),第 i 条边连接节点 u_i 和 v_i,权重为 w_i。最初,所有节点都未激活。你需要处理 q 个操作,每次询问操作后要输出将所有激活点连接起来的最小边权和。
操作分三种:
T u:切换节点 u 的激活状态(若原来非激活则激活,激活则变为非激活)。A u v val: 将节点 u 和 v 之间的简单路径加 val。Q:询问将所有激活点连接起来的最小边权和。
输入格式Input
第一行:两个整数 n 和 q。(1\le n,q\le2\times10^5)
接下来 n-1 行,每行三个整数 u_i,v_i,w_i 表示一条无向边,1\le u_i,v_i\le n,1 \le w_i\le10^6。
接下来 q 行,每行要么是
T u:切换节点 u 的激活状态;A u v val: 将节点 u 和 v 之间的简单路径加 val ,1 \le val \le100。Q:输出将所有激活点连接起来的最小边权和。
输出格式Output
对于每个 Q
操作,输出一行一个整数——最小边权和;若激活节点数少于 2,则输出
0。
样例Sample
出题Author
xxy