Address: http://codevs.cn/problem/1501/
First contact with the tree.
Fortunately, the node of this problem is certain, not arbitrarily set. (In fact, the Internet to find the correct understanding of the wrong idea.) )
So do not think so much with deep search.
Otherwise I can't do it for the time being.
#include <iostream>
using namespace std;
int width[10], tree[20][2];
int Layernum, widthnum;
void Dfs (int i, int layer) {//i is the number of nodes
width[layer]++;//each more node, the width of the corresponding layer is plus 1
if (Layer > Layernum) layernum = Layer //To determine the maximum number of layers
if (tree[i][0]!= 0) DFS (tree[i][0], layer + 1);
if (Tree[i][1]!= 0) DFS (tree[i][1], layer + 1);
}
int main () {
int n;
CIN >> N;
for (int i = 1; I <= n; i++) {
cin >> tree[i][0] >> tree[i][1];
}
Layernum = 0;
DFS (1, 1);
for (int i = 1; I <= n; i++) {
if (Width[i] > Widthnum) widthnum = Width[i];
cout << widthnum << "" << layernum;
return 0;
}