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.
# | 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 |
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.
Name |
---|
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