Hello everyone!
Having found the SCC of a directed graph G, how can I contract each SCC to a single node?
Thanks.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
10 | nor | 152 |
Hello everyone!
Having found the SCC of a directed graph G, how can I contract each SCC to a single node?
Thanks.
Название |
---|
Suppose you know C[v] — which component contains node v.
Now you scan through edges of the original graph, let current one be x->y.
Then you should add an edge C[x]->C[y] in compressed graph if C[x] is not equal to C[y].
Yes, and you should also remember to mark which edges have already been added so you don't double count any edge. You can use a boolean array or an edge set
What's so bad about keeping a multi-edge in DAG? :P
If we have to do some traversal in the compressed graph we are going to waste some operations while scanning the adjacency list of each vertex :P
I'd rather use disjoint sets. It doesn't require too much memory and I think it's faster than an edge set :D and are VERY easy to code
How can i use disjoint sets for this purpose? I have never seen this application, i usually use DSU for Kruskal's only :P
Nvm, bullsh*t in rev1
Awesome! It's really simple, you are right, this is the easiest/most efficient option.
But if you have edges X->Y, Y->Z, X->Z, won't you miss one of them this way?
omg you are right, I remember I used disjoint sets but it wasn't this way. Nvm thanks!
Other valid option would be using a hash function so you can check in O(1) whether the edge exists or not! It should be easy to come up with a function that wont generate collisions since amount of edges is usually small :)
EDIT : never used unordered set, but this may actually be the implementation of what i said above
UPD: I am sorry, there is nothing correct here :(
Won't it be more efficient supposing there won't be collisions? I'm assuming you will use map data structure to associate integers to each edge
I am sorry, I have no idea what I was thinking at that moment but I suppose it was something wrong :(