diff --git a/Cpp/1319-Number-of-Operations-to-Make-Network-Connected/BFSsolution.cpp b/Cpp/1319-Number-of-Operations-to-Make-Network-Connected/BFSsolution.cpp new file mode 100644 index 0000000..ee09f2e --- /dev/null +++ b/Cpp/1319-Number-of-Operations-to-Make-Network-Connected/BFSsolution.cpp @@ -0,0 +1,40 @@ +class Solution { +public: + int makeConnected(int n, vector>& c) { + int edges = c.size();; + + if( edges < n - 1 ){ + return -1; + } + + vector adj[n]; + vector vis(n, 0); + + for( int i=0; i < c.size(); i++ ) { + adj[ c[i][0] ].push_back( c[i][1] ); + adj[ c[i][1] ].push_back( c[i][0] ); + } + queue q; + int count = 0; + + for(int i = 0; i