i saw a video in youtube which was stating that using nested maps will give you error in some of problems because of online judges so shall i not make that as a habbit as i am new in graph
and if you have some tips to share on how to study graph please do i! thanks
I prefer to use an adjacency list to represent trees and graphs as I find it easier to implement and use,
int MAXN = int(1e3);
vector<int> adj[MAXN];
void add_undirected_edge(int a, int b, vector<int> adj[]) {
adj[a].push_back(b);
adj[b].push_back(a);
return;
}
You can manipulate it to store directed edges, weights and all sort of things.
thanks bro can you also tell me where and how you practiced graph problems ;
Upsolving problems related to graphs after the contest helps more than anything else. However I would suggest you to practice on Leetcode, SPOJ, CodeForces and CC as they have decent problems related to graphs. And you can always refer to this blog.
Additional tool : Graph Editor CSAcademy for visualising graphs.
Happy Coding ;