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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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.