atcoder#ABC214H. [ABC214H] Collecting
[ABC214H] Collecting
Score : points
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.
5 5 2
1 2
2 3
3 2
1 4
1 5
1 4 5 2 8
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 .
3 1 10
2 3
1 100 100
1