求调 15 pts
查看原帖
求调 15 pts
1403682
Helenty楼主2025/8/3 21:40

如题,代码如下:

#include <bits/stdc++.h>
using namespace std;

int T, n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while (T--)
	{
        cin >> n;
        if (!(n - 1))
		{
            cout << "0\n";
            continue;
        }
        vector<int> a(n + 1, 0);
        for (int i = 0; i < n - 1; ++i)
		{
            int u, v;
            cin >> u >> v;
            a[u]++, a[v]++;
        }
        if (*max_element(a.begin() + 1, a.end()) <= 2) cout << "1\n";
        else cout << "2\n";
    }
    return 0;
}
2025/8/3 21:40
加载中...