online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; class graph{ int v; map<int,list<int>> l; public: graph(int v) { this->v=v+1; } void addEdge(int x,int y) { l[x].push_back(y); l[y].push_back(x); } void dfs_helper(bool*visited,int*children,int src) { visited[src]=true; for(auto nbr : l[src]) { if(!visited[nbr]) { children[src]+=1; dfs_helper(visited,children,nbr); } } } int DFS() { bool* visited=new bool[v]; int* children= new int[v]; for (int i=0;i<v;i++) { visited[i]=false; children[i]=0; } int src=1; int ans=0; dfs_helper(visited,children,src); for(int i=1;i<v;i++){ for(auto nbr : l[i]) { if(children[nbr]>children[i]) ans++; } } return ans; } }; int main() { int n,m; cin>>n>>m; graph g(n); while(m--) { int x,y; cin>>x>>y; g.addEdge(x,y); } cout<<g.DFS()<<endl; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue