I want to print the level of last node. I am new to STL and Graph Theory so help me out in finding out the level of the last node of graph. Probably done the algorithm correct but still some issues with vectors in STL and suggest me how to print the level of the last node.
Here is my code:
// Sample code to perform I/O:
#include<bits/stdc++.h>
using namespace std;
int N,M;
vector <int> adj[100];
bool visited[100];
vector <int> level[100];
void initialize();
int main() {
cin>>N>>M;
int x,y;
while(M--)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
initialize();
for(int i=0;i<N;i++)
{
if(visited[i] == false)
{
list <int> q;
q.push_back(i);
while(!q.empty())
{
int p=q.front();
q.pop_front();
for(int j=0;j<adj[p].size();j++)
{
if(visited[adj[p][j]] == false)
{
level[adj[p][j]] = level[adj[p]] + 1;
q.push_back(adj[p][j]);
visited[adj[p][j]] == true;
}
}
}
}
}
}
void initialize()
{
for(int i=0;i<N;i++)
visited[i]=false;
}
And my errors are:
In function ‘int main()’: 36:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
40:53: error: no match for ‘operator[]’ (operand types are ‘std::vector [100]’ and ‘std::vector’)
42:48: warning: value computed is not used [-Wunused-value]
Help me out to solve this