Memset Error(STL)


why am i getting error in memset() line

@dare_devil_007, you have to include cstring library (#include )
also you are calling function inside class body which will generate error ("ISO C++ forbids declaration of ‘memset’ with no type ") as class is a blueprint for its object so you can;t call any function inside class body instead you should call memset inside dfs() function

also is this the code for connected component in undirected graph ??

yeah bro!!thanx will try and let you know if there r any doubts


https://codeforces.com/contest/977/problem/E
i am nt able to get where i am going wrong,when i am trying to output the connected comonents,some edges are missing why?

@dare_devil_007, there are two mistakes in your code ;-

  1. you are should be checking indegrees of node for every connected component so put that code inside the if(!visited[v]){ condition

  2. you are increasing the count when flag is 1 but it should be increased when flag is not 1 as flag is set when we find a node with indegree !=2

corrected code :-

my advice would be to try to write code cleaner so it will be much easier for you to find mistakes , also you can refer to my code i have used a similar concept but with easy and efficient implementation

My code:-

In case of any doubt feel free to ask :slight_smile:
Mark your doubt as RESOLVED if you got the answer

thanks a lot bro and yeah thanks for your valuable advice.Now i understood the code and there is one small doubt
vector*adj;
adj=new vector[n+1];

what is being done int the above lines?

adj = new vector[n+1], here i am dynamically allocating array of vectors of size n

eg :-
when we do
int* a;
a = new int[n ];
we dynamically allocate an integer array
so since vector is also a data type we can allocate vector array

this is used to make adjacency list
you can use list or map for that