#include #include #include #include #include using namespace std; int main() { int Q; cin >> Q; while (Q--) { int N; cin >> N; vector > G(N); for (int i = 0; i < N - 1; ++i) { int a, b; cin >> a >> b; --a, --b; G[a].push_back(b); G[b].push_back(a); } function(int)> shortest_path = [&](int pos) { queue que; que.push(pos); vector resdist(N, -1); resdist[pos] = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (int i : G[u]) { if (resdist[i] == -1) { resdist[i] = resdist[u] + 1; que.push(i); } } } return resdist; }; vector v0 = shortest_path(0); int p1 = max_element(v0.begin(), v0.end()) - v0.begin(); vector v1 = shortest_path(p1); int diameter = *max_element(v1.begin(), v1.end()); int degree1 = 0; for (int i = 0; i < N; ++i) { if (G[i].size() == 1) { ++degree1; } } cout << (diameter < degree1 ? "Yes" : "No") << endl; } return 0; }