TheAlgorithms / C-Plus-Plus

Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
https://thealgorithms.github.io/C-Plus-Plus
MIT License
30.79k stars 7.29k forks source link

Depth First Search #2814

Open Arjuns-create opened 1 month ago

Arjuns-create commented 1 month ago

Detailed description

There is a problem on depth first search so i want to create and push my own code

Context

Other users use my code and help them to understand

Possible implementation

include<bits/stdc++.h>

using namespace std;

vector vis;
vector<vector> g;

void dfs(int node) { vis[node] = 1;

for(auto v : g[node]) {
    if(!vis[v]) {
        dfs(v);  
    }
}

}

int main() { int n, m;
cin >> n >> m;

g.resize(n + 1);  
vis.resize(n + 1, 0);  

for(int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);  
}

for(int i = 1; i <= n; i++) {
    if(!vis[i]) {
        dfs(i);
    }
}

return 0;

}

Additional information

No response

HAAGIMARU-29 commented 1 month ago

can you please assign this issue to me ?

Arjuns-create commented 1 month ago

can you please assign this issue to me ?

okayy

mihir-k64 commented 1 month ago

assign this me to me please under hacktober tag

Divyansh-jain2 commented 1 month ago

assign this to me

github-actions[bot] commented 6 days ago

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.