#include<queue>
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children;
Node() {}
Node(int _val, vector<Node*> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
vector<vector<int>> levelOrder(Node* root) {
vector<vector<int>> res;
if(root==NULL)return vector<vector<int>>();
queue<Node*> s;
queue<int> height;
int current = 0;
s.push(root);
vector<int> level;
height.push(0);
while(!s.empty())
{
Node *tmp = s.front();
int h = height.front();
if(current!=h)
{
res.push_back(level);
level.clear();
level.push_back(tmp->val);
current ++;
}
else
{
level.push_back(tmp->val);
}
vector<Node*> child;
child = tmp->children;
int l = child.size();
int i =0;
while(i<l)
{
s.push(child[i]);
height.push(h+1);
i++;
}
s.pop();
height.pop();
}
res.push_back(level);
return res;
}
};