Advertisement
fooker

P1167C

Nov 21st, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. ll counter=0;
  5. vector<ll> adj[500000];
  6. bool visited[500000];
  7. void dfs(ll c){
  8.     counter++;
  9.     visited[c]=true;
  10.     for (auto u:adj[c]){
  11.         if (!visited[u]){
  12.             dfs(u);
  13.         }
  14.     }
  15. }
  16. int main()
  17. {
  18.     ll n,m;
  19.     cin>>n>>m;
  20.     vector<ll> v[m];
  21.     for (ll i=0; i<m; i++){
  22.         ll x;
  23.         cin>>x;
  24.         for (ll j=0; j<x; j++){
  25.             ll y;
  26.             cin>>y;
  27.             v[i].push_back(y);
  28.         }
  29.         for (ll l=0; l<v[i].size(); l++){
  30.             for (auto k:v[i]){
  31.                 if (v[i][l]!=k){
  32.                     adj[v[i][l]].push_back(k);
  33.                 }
  34.             }
  35.         }
  36.     }
  37.     for (ll i=1; i<=n; i++){
  38.         dfs(i);
  39.         cout<<counter<<" ";
  40.         counter=0;
  41.         visited[500000]=false;
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement