Category : adjacency-list

#include <bits/stdc++.h> using namespace std; //This function does not work as i intended it to. It should add the node a to the list of b and vice versa(an undirected graph. void addNewEdge(vector<vector <int>> adjacencyList,int a,int b, vector<bool> isVisited){ adjacencyList[a].push_back(b); adjacencyList[b].push_back(a); isVisited[a] = false; isVisited[b] = false; } //the following function is meant to mark ..

Read more

I got this error no match for ‘operator=’ (operand types are ‘listNode’ and ‘listNode*’) in code G->adj[i]=(struct listNode *)malloc(sizeof(struct listNode)); I was representing graph data structure in the adjacency list. #include <iostream> using namespace std; struct listNode{ int value; struct lsitNode * next; }; struct Graph{ int V; int E; struct listNode *adj; }; struct ..

Read more

I’m successfully using boost graph’s component finder to assign color, i.e. the component’s index to every vertex in my graph like so: #include <boost/graph/connected_components.hpp> #include <boost/graph/adjacency_list.hpp> boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS> g; std::vector<int> compon_map(boost::num_vertices(g)); int number_of_components = boost::connected_components(g, &compon_map[0]); This will then yield a different number_of_components after each iteration in my simulation (not shown) because I do ..

Read more

#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n>> m; vector<vector<int>> adj( 1001 , vector<int> (1001, 0)); for(int i=0;i<m;i++){ int a,b; cin>> a>>b; adj[a][b]=1; adj[b][a]=1; } int q; cin>>q; while(q–){ int a,b; cin>>a>>b; if(adj[a][b]==1) cout <<"YES" <<endl; else cout << "NO" <<endl; } } The 2-D vector part is giving segmentation fault.Even though ..

Read more