QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644961#6421. Degree of Spanning Treerush-from-behind#WA 111ms5968kbC++231.7kb2024-10-16 16:13:102024-10-16 16:13:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 16:13:11]
  • 评测
  • 测评结果:WA
  • 用时:111ms
  • 内存:5968kb
  • [2024-10-16 16:13:10]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T &x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T &x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 2e5 + 10;
int n, m, deg[N], fa[N], dd[N];
// vector <int> v[N];
pair <int, int> e[N];
int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
void zhk() {
	cin >> n >> m;
	F(i, 1, n) deg[i] = dd[i] = 0, fa[i] = i;
	F(i, 1, m) {
		cin >> e[i].first >> e[i].second;
		deg[e[i].first]++;
		deg[e[i].second]++;
		// int x, y; cin >> x >> y;
	}
	sort(e + 1, e + m + 1, [&] (pair <int, int> x, pair <int, int> y) {
		return deg[x.first] + deg[x.second] < deg[y.first] + deg[y.second];
	});
	vector <pair <int, int>> ans;
	F(i, 1, m) {
		int x = find(e[i].first), y = find(e[i].second);
		if (x == y) continue;
		ans.push_back(e[i]);
		fa[x] = y;
		dd[x]++, dd[y]++;
	}
	F(i, 1, n)
		if (dd[i] > n / 2) {
			cout << "No\n";
			return;
		}
	cout << "Yes\n";
	for (auto [a, b]: ans) cout << a << ' ' << b << '\n';
}
signed main() {
	ios::sync_with_stdio(0); // don't use puts
	cin.tie(0), cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5648kb

input:

2
6 9
1 2
1 3
1 4
2 3
2 4
3 4
4 5
4 6
4 6
3 4
1 3
2 3
3 3
1 2

output:

Yes
1 2
1 3
4 5
4 6
1 4
No

result:

ok 2 cases

Test #2:

score: -100
Wrong Answer
time: 111ms
memory: 5968kb

input:

11140
10 15
9 6
5 7
6 5
2 3
7 5
7 5
3 10
9 7
5 5
9 1
7 5
2 8
7 5
4 3
6 2
9 19
3 7
3 9
2 8
2 8
3 6
5 1
1 8
8 9
8 3
4 8
5 5
3 1
4 3
1 3
8 6
1 3
7 4
4 3
8 8
12 20
10 2
5 5
2 4
3 3
3 3
5 11
9 2
5 5
7 12
11 3
3 3
3 5
5 3
3 1
4 6
7 11
6 8
4 5
6 12
6 5
8 18
4 2
4 3
2 4
2 4
4 3
4 8
2 2
6 7
2 4
6 2
1 4
8 7
4...

output:

Yes
3 10
9 1
2 8
4 3
9 6
2 3
6 2
9 7
6 5
Yes
7 4
5 1
3 9
2 8
3 6
8 9
3 7
1 3
Yes
10 2
9 2
7 12
6 8
7 11
2 4
6 12
4 6
3 1
5 11
11 3
No
Yes
4 3
2 3
8 7
1 2
2 9
9 7
1 5
6 7
Yes
8 10
3 2
1 9
2 5
1 7
10 2
2 6
4 6
6 1
Yes
5 4
2 6
4 6
5 7
7 1
5 3
Yes
3 13
11 13
12 3
9 10
5 4
7 12
12 6
10 7
2 6
11 1
8 5
8 1...

result:

wrong answer case 4, participant does not find a solution but the jury does