A15731 | Colorful Tree Again
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
An edge-weighted tree of $n$ nodes is given with each edge colored in some color. Each node of this tree can be blocked or unblocked, all nodes are unblocked initially.
A simple path is a path in a graph that does not have repeating nodes. The length of a path is defined as the sum of weights of all edges on the path.
A path is good when it is a simple path consisting of edges of the same color $c$ , all edges of color $c$ are on this path, and every node on the path is unblocked.
You need to operate $2$ kinds of queries:
1. block a node,
2. unblock a node.
After each query, print the maximum length among all good paths. If there are no good paths, print $0$ .
A simple path is a path in a graph that does not have repeating nodes. The length of a path is defined as the sum of weights of all edges on the path.
A path is good when it is a simple path consisting of edges of the same color $c$ , all edges of color $c$ are on this path, and every node on the path is unblocked.
You need to operate $2$ kinds of queries:
1. block a node,
2. unblock a node.
After each query, print the maximum length among all good paths. If there are no good paths, print $0$ .
输入格式
The first line contains two integers $n$ , $q$ ( $1 \leq n,q \leq 2\cdot 10^5$ ) — the number of nodes and the number of queries.
Then $n-1$ lines follow, each containing four integers $u$ , $v$ , $w$ and $c$ ( $1 \leq u,v,w,c \leq n$ ; $u \not = v$ ), denoting a weighted edge connecting node $u$ and node $v$ with weight $w$ and color $c$ . It is guaranteed that these edges form a tree.
Then $q$ lines follow, each containing two integers $p$ and $x$ ( $p = 0$ or $p = 1$ , $1\leq x\leq n$ ), denoting a query:
1. if $p = 0$ , block the node $x$ . It's guaranteed that it's not blocked at this time;
2. if $p = 1$ , unblock the node $x$ . It's guaranteed that it's blocked at this time.
Then $n-1$ lines follow, each containing four integers $u$ , $v$ , $w$ and $c$ ( $1 \leq u,v,w,c \leq n$ ; $u \not = v$ ), denoting a weighted edge connecting node $u$ and node $v$ with weight $w$ and color $c$ . It is guaranteed that these edges form a tree.
Then $q$ lines follow, each containing two integers $p$ and $x$ ( $p = 0$ or $p = 1$ , $1\leq x\leq n$ ), denoting a query:
1. if $p = 0$ , block the node $x$ . It's guaranteed that it's not blocked at this time;
2. if $p = 1$ , unblock the node $x$ . It's guaranteed that it's blocked at this time.
输出格式
For each query, print the maximum length of a good path. If there are no good paths, print $0$ .
输入输出样例
输入 #1
5 4 4 1 3 4 5 2 4 4 3 1 3 2 1 2 5 1 0 4 0 3 0 2 1 3
输出 #1
5 5 0 3
输入 #2
5 5 4 1 4 4 4 5 2 2 3 1 2 4 3 2 3 1 0 3 0 4 1 3 1 4 0 1
输出 #2
2 0 3 6 3
输入 #3
6 9 3 2 2 3 2 4 4 2 3 1 5 5 6 4 3 2 5 3 1 3 0 2 0 4 0 5 0 6 1 2 1 4 1 5 0 3 1 6
输出 #3
5 5 5 5 5 5 5 0 7
输入 #4
1 2 0 1 1 1
输出 #4
0 0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted