A12064 | Pisces
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A group of researchers are studying fish population in a natural system of lakes and rivers. The system contains $n$ lakes connected by $n - 1$ rivers. Each river has integer length (in kilometers) and can be traversed in both directions. It is possible to travel between any pair of lakes by traversing the rivers (that is, the network of lakes and rivers form a tree).
There is an unknown number of indistinguishable fish living in the lakes. On day $1$ , fish can be at arbitrary lakes. Fish can travel between lakes by swimming the rivers. Each fish can swim a river $l$ kilometers long in any direction in $l$ days. Further, each fish can stay any number of days in any particular lake it visits. No fish ever appear or disappear from the lake system. Each lake can accomodate any number of fish at any time.
The researchers made several observations. The $j$ -th of these observations is "on day $d_j$ there were at least $f_j$ distinct fish in the lake $p_j$ ". Help the researchers in determining the smallest possible total number of fish living in the lake system that doesn't contradict the observations.
There is an unknown number of indistinguishable fish living in the lakes. On day $1$ , fish can be at arbitrary lakes. Fish can travel between lakes by swimming the rivers. Each fish can swim a river $l$ kilometers long in any direction in $l$ days. Further, each fish can stay any number of days in any particular lake it visits. No fish ever appear or disappear from the lake system. Each lake can accomodate any number of fish at any time.
The researchers made several observations. The $j$ -th of these observations is "on day $d_j$ there were at least $f_j$ distinct fish in the lake $p_j$ ". Help the researchers in determining the smallest possible total number of fish living in the lake system that doesn't contradict the observations.
输入格式
The first line contains a single integer $n$ ( $1 \leq n \leq 10^5$ ) — the number of lakes in the system.
The next $n - 1$ lines describe the rivers. The $i$ -th of these lines contains three integers $u_i$ , $v_i$ , $l_i$ ( $1 \leq u_i, v_i \leq n$ , $u_i \neq v_i$ , $1 \leq l_i \leq 10^3$ ) — $1$ -based indices of lakes connected by the $i$ -th river, and the length of this river.
The next line contains a single integer $k$ ( $1 \leq k \leq 10^5$ ) — the number of observations.
The next $k$ lines describe the observations. The $j$ -th of these lines contains three integers $d_j$ , $f_j$ , $p_j$ ( $1 \leq d_j \leq 10^8$ , $1 \leq f_j \leq 10^4$ , $1 \leq p_j \leq n$ ) — the day, the number of fish, and the lake index of the $j$ -th observation. No two observations happen on the same day at the same lake simultaneously.
The next $n - 1$ lines describe the rivers. The $i$ -th of these lines contains three integers $u_i$ , $v_i$ , $l_i$ ( $1 \leq u_i, v_i \leq n$ , $u_i \neq v_i$ , $1 \leq l_i \leq 10^3$ ) — $1$ -based indices of lakes connected by the $i$ -th river, and the length of this river.
The next line contains a single integer $k$ ( $1 \leq k \leq 10^5$ ) — the number of observations.
The next $k$ lines describe the observations. The $j$ -th of these lines contains three integers $d_j$ , $f_j$ , $p_j$ ( $1 \leq d_j \leq 10^8$ , $1 \leq f_j \leq 10^4$ , $1 \leq p_j \leq n$ ) — the day, the number of fish, and the lake index of the $j$ -th observation. No two observations happen on the same day at the same lake simultaneously.
输出格式
Print one integer — the smallest total number of fish not contradicting the observations.
输入输出样例
输入 #1
4 1 2 1 1 3 1 1 4 1 5 1 1 2 1 1 3 2 2 1 3 1 4 3 1 2
输出 #1
2
输入 #2
5 1 2 1 1 3 1 1 4 1 1 5 1 4 1 1 2 2 1 3 3 1 4 4 1 5
输出 #2
2
输入 #3
5 2 5 1 5 1 1 2 4 1 5 3 3 6 5 2 4 2 1 1 2 1 3 2 2 4 4 7 5 4 1 2
输出 #3
10
In the first example, there could be one fish swimming through lakes $2$ , $1$ , and $4$ , and the second fish swimming through lakes $3$ , $1$ , and $2$ .
In the second example a single fish can not possibly be part of all observations simultaneously, but two fish swimming $2 \to 1 \to 4$ and $3 \to 1 \to 5$ can.
In the third example one fish can move from lake $1$ to lake $5$ , others staying in their lakes during all time: two fish in lake $4$ , six fish in lake $5$ , one fish in lake $3$ . The system of lakes is shown on the picture.

In the second example a single fish can not possibly be part of all observations simultaneously, but two fish swimming $2 \to 1 \to 4$ and $3 \to 1 \to 5$ can.
In the third example one fish can move from lake $1$ to lake $5$ , others staying in their lakes during all time: two fish in lake $4$ , six fish in lake $5$ , one fish in lake $3$ . The system of lakes is shown on the picture.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted