DFS
We traverse the tree using the dfs function, which returns:\n- the number of nodes in the tree if it\'s perfect.\n- -1 otherwise.\n\nFor each node, we compare t
We traverse the tree using the `dfs` function, which returns:\n- the number of nodes in the tree if it\'s perfect.\n- `-1` otherwise.\n\nFor each node, we compare the result for the left `l` and right `r` subtrees.\n\nIf both subtrees are perfect with the same number of nodes (`l == r`), we add `l + r + 1` to the `perf` array.\n\nIn the end, we use the `perf` array to get the k-th largest perfect subtree size.\n\n**C++**\n```cpp\nvector<int> perf;\nint dfs(TreeNode* n) {\n    if (n == nullptr)\n        return 0;\n    if (int l = dfs(n->left), r = dfs(n->right); l == r) {\n        perf.push_back(l + r + 1);\n        return l + r + 1;\n    }\n    return -1;\n}\nint kthLargestPerfectSubtree(TreeNode* root, int k) {\n    dfs(root);\n    if (perf.size() < k)\n        return -1;\n    nth_element(begin(perf), begin(perf) + k - 1, end(perf), greater{});\n    return perf[k - 1];\n}\n```
['C']