Demo entry 6716889

c++

   

Submitted by dxt on Feb 22, 2018 at 12:31
Language: C++. Code size: 717 Bytes.

#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
int N,M,ro,x,y;
std::vector<int> v[105];
int level[100];
int MAX_level=-1;
void dfs(int root,int le){
	if(le>MAX_level)MAX_level=le;
	if(v[root].size()==0){
		level[le]++;
		return;
	}
	for (int i = 0; i <v[root].size(); ++i)
		dfs(v[root][i],le+1);
	
}
int main(int argc, char const *argv[])
{
	scanf("%d%d",&N,&M);
	for (int i = 0; i <M; ++i){
		scanf("%d%d",&ro,&x);
		for (int j = 0; j <x; ++j){
			scanf("%d",&y);
			v[ro].push_back(y);
		}
	}
	dfs(1,0);
	for (int i = 0; i <=MAX_level; ++i)
	{
		if(i!=0)printf(" ");
		printf("%d",level[i]);
	}
	system("pause");
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).