I have recently learnt the technique to find strongly connected components in directed graph so i was trying this problem but i can't find solution.
Can you help me solve this problem?
Thanks in advance.
Happy Coding :)
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I have recently learnt the technique to find strongly connected components in directed graph so i was trying this problem but i can't find solution.
Can you help me solve this problem?
Thanks in advance.
Happy Coding :)
Name |
---|
I don't know how to solve this problem but I think you can use DP or DFS.
This is how I did it
First of all find all the strongly connected components.The path that you will follow is would be like u -> v -> .... -> y where u is SCC of start node and y is SCC of end node, in between you would come accross a number (>=0) of other SCC's as well. The point is if you will go at node h then you will go to all vertices of h's SCC to maximize the value.
So path has been stated by me in terms of SCC. Note that after getting the SCC's if we consider each SCC as a node of some new graph then this new graph would be a directed acyclic graph where value of a SCC node is sum of values of all the nodes in it,
The problem now reduces to finding a path from start node's SCC to end node's SCC with maximum value. To do this we will only consider SCC nodes which are in subgraph of the new graph whose root is start node's SCC. Once we have this subgraph the problem reduces to find maximum value in going from root to end node's SCC.
This can now be done by dynamic programming by traversing SCC nodes in the topological sorting manner.
Please pardon my poor english. I feel I might not be clear beacuse of the long solution. Feel free to reach out for any explainations.
Hope it helps :)
Thanks man! I got your approach.