int lastSize = seq.size(); while (!seq.empty()) { for (int i = 0; i < node->successors.size(); i++) if (!node->successors[i]->visited && node->successors[i]->subtree[seq.front()]) { traverseTree(node->successors[i], seq); break; } if (lastSize == seq.size()) break; lastSize = seq.size(); } }
intmain(){ int T = 0; cin >> T; for (int i = 0; i < T; i++) { int n = 0, m = 0; cin >> n; Node* nodes = new Node[n + 1]; for (int i = 1; i < n + 1; i++) nodes[i].id = i; for (int i = 0; i < n - 1; i++) { int a = 0, b = 0; cin >> a >> b; nodes[a].successors.push_back(nodes + b); nodes[b].successors.push_back(nodes + a); } cin >> m; queue<int> sequence; for (int i = 0; i < m; i++) { int a = 0; cin >> a; sequence.push(a); } Tree tree = Tree(nodes + 1);