Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
907 B
1
Indexable
Never
#include <bits/stdc++.h>
using namespace std;


int main (){
	int n, p[100010] = {0}, h[100010] = {0};
	vector <int> v;
	cin >> n;
	for(int i=1; i<=n; i++){
		int chnum;
		cin >> chnum;
		if(chnum==0) v.push_back(i);
		for(int j=1; j<=chnum; j++){
			int ch;
			cin >> ch;
			p[ch] = i;
		}
	}int i=1; i<=n; i++) cout << p[i] << " "; 
	
	//test for cin parent of child
	//for(
	int root;
	for(int i=1; i<=n; i++){
		if(p[i] == 0){
			root = i;
			break;
		}
	}
	cout << root << "\n";
	//test the num of root
	//cout << "root is = " << root << "\n";
	
	//test vector v inside
	/*cout << "test v \n";
	for(auto i:v) cout << i << "  "; 
	cout << "\n";*/
	

	int totalh=0, cnt;
	for(int i=0; i<v.size(); i++){	
		cnt = 0;
		for(int j=v[i]; j!=0; j=p[j]){
			h[j] = max(h[j], cnt++);
		}
	}
	
	for(int i=1; i<=n; i++) totalh += h[i];
	cout << totalh << "\n";
	
}