Skip to content

Instantly share code, notes, and snippets.

@SandeepTuniki
Last active October 16, 2016 04:06
Show Gist options
  • Save SandeepTuniki/bef0a63a55564fe6649aca25737b87ca to your computer and use it in GitHub Desktop.
Save SandeepTuniki/bef0a63a55564fe6649aca25737b87ca to your computer and use it in GitHub Desktop.
Graph Template for c++
struct Node {
int id;
unordered_map<int, *Node> neighbours;
};
struct Edge {
Node *source;
Node *dest;
int weight;
};
struct Graph {
unordered_map<int, *Node> nodes;
unordered_map< pair<int, int>, *Edge > edges;
};
/*
Useful when the graph is undirected, and has same edge-lengths across the network.
Used for problems like DFS, BFS
*/
struct Graph {
int n, m;
vector<list<int>> neighbours;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment