Skip to main content

Posts

Showing posts with the label sphere online judge

Spoj Solutions

  1.CAM5 - prayatna PR Spoj Solution TAG- graph theory,Disjoint set union,dfs. Explanation- We have to group the people which are connected in any other way and there is hint when we talk about grouping . One way to solve the problem is using DFS or Disjoint set union. Solution Using DFS- #include<bits/stdc++.h> using namespace std; #define ll long long int  #define str string #define pb push_back #define vc vector #define ci cin #define co cout bool vis[1000010]; void dfs(ll src,vector<ll>adj[]) {     vis[src]=true;     for(auto u:adj[src])     {         if(!vis[u])             dfs(u,adj);     } } int main() {        ios_base::sync_with_stdio(false);     cin.tie(NULL);     ll t;     cin>>t;     while(t--)     {         ll n,m;         cin>>n>>m; ...