#abc214h. H - Collecting
H - Collecting
Score : points
问题描述
存在一个含有 个顶点和 条边的有向图。
顶点编号为 ,第 条边()从顶点 指向顶点 。
最初,在顶点 上有 件物品被某人丢失()。将会有 个人来收集这些物品。
这 个人将依次在图中移动。每个人将执行以下操作:
- 从顶点 开始,然后可以任意多次遍历边。对于访问过的每个顶点(包括顶点 ),如果它们上面的物品尚未被收集,则收集所有物品。
找出能够收集到的最大物品总数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a directed graph with vertices and edges.
The vertices are numbered , and the -th edge goes from Vertex to Vertex .
Initially, there are items on Vertex that someone has lost. people will collect these items.
The people will travel in the graph one by one. Each person will do the following.
- Start on Vertex . Then, traverse an edge any finite number of times. For each vertex visited (including Vertex ), collect all items on it if they have not been collected yet.
Find the maximum total number of items that can be collected.
Constraints
- or , if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 5 2
1 2
2 3
3 2
1 4
1 5
1 4 5 2 8
Sample Output 1
18
The two people can collect items as follows.
- The first person goes and collects the items on Vertices , , and .
- The second person goes and collects the items on Vertex .
It is impossible to collect or more items, so we should print .
Sample Input 2
3 1 10
2 3
1 100 100
Sample Output 2
1
update @ 2024/3/10 09:32:22