How to implement weighted Graph in c++ for higher values of n = 10^5 (n vertices graph)?? If n = 10^3 i generally implement using adjacency matrix or by using vector stl.
№ | Пользователь | Рейтинг |
---|---|---|
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 | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
How to implement weighted Graph in c++ for higher values of n = 10^5 (n vertices graph)?? If n = 10^3 i generally implement using adjacency matrix or by using vector stl.
Название |
---|
You can implement it using adjacency lists. Something as simple as this works...
Thanks a lot!!
It only works for a directional graph.
i think you need to understand how the code above works instead of just taking it its basically creating an array of vectors every slot of the array represent a node so lets say i want to add a link from node u to node v then i will just push v in the uth slot thats why i need to do something like this: e[u].push_back({v, whatever_weight}) now, we want to make undirected graph just instead just adding u to slot v we also add v to slot u so conclusion just add e[v].push_back({u, w}) as well to make an undirected graph
no it isnt
My bad
no