General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
55075296 Practice:
kush_76
1167C - 17 GNU C++11 Time limit exceeded on test 3 2000 ms 23620 KB 2019-06-04 11:18:10 2019-06-04 11:18:10
 
 
→ Source
#include <bits/stdc++.h>
using namespace std;
map<int,list<int> >adjlist;
map<int,bool>visited;
int bfs(int src){

     int ans = 0;
     visited[src] = true;
     queue<int>q;
     q.push(src);
     while(!q.empty()){

         int node = q.front();
         q.pop();
         ans++;
         for(auto i : adjlist[node]){

             if(visited[i]==false){

                 visited[i] = true;
                 q.push(i);
             }
         }
     }
     return ans;
}
int main() {
  int n,m,k,i;
  cin >> n >> m;
  for(i=1;i<=m;i++){

    //  int k;
      cin >> k;

      //    cout << k << endl;
          vector<int>v;
          for(int j=0;j<k;j++){

              int x;
              cin >> x;
              v.push_back(x);
          }
          for(int j=1;j<k;j++){

              adjlist[v[j]].push_back(v[j-1]);
              adjlist[v[j-1]].push_back(v[j]);
          }
      }
    for(int i=1;i<=n;i++){

       // ans = 0;
        visited.clear();
        cout << bfs(i)  << " ";
    }
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details