Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll counter=0;
- vector<ll> adj[500000];
- bool visited[500000];
- void dfs(ll c){
- counter++;
- visited[c]=true;
- for (auto u:adj[c]){
- if (!visited[u]){
- dfs(u);
- }
- }
- }
- int main()
- {
- ll n,m;
- cin>>n>>m;
- vector<ll> v[m];
- for (ll i=0; i<m; i++){
- ll x;
- cin>>x;
- for (ll j=0; j<x; j++){
- ll y;
- cin>>y;
- v[i].push_back(y);
- }
- for (ll l=0; l<v[i].size(); l++){
- for (auto k:v[i]){
- if (v[i][l]!=k){
- adj[v[i][l]].push_back(k);
- }
- }
- }
- }
- for (ll i=1; i<=n; i++){
- dfs(i);
- cout<<counter<<" ";
- counter=0;
- visited[500000]=false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement