static int process(FM root, FM[] fms, int maxLevel) {
		int level = maxLevel;
		for(int c : root.children) {
			FM fmc = fms[c];
			if(fmc == null) {
				//it has to be leaf node
				fmc = new FM(root.level + 1);
				fms[c] = fmc;
				if(fmc.level > level) {
					level = fmc.level;
				}
			} else {
				// it may or may not a leaf node, but it doesn't matter here, just update its level
				fmc.level = root.level + 1;
				if(level < fmc.level) {
					level = fmc.level;
				}
				int rtLevel = process(fmc, fms, level);
				if(rtLevel > level) {
					level = rtLevel;
				}
			}
		}
		return level;
	}