QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#165067#2437. Wireless is the New FiberPetroTarnavskyi#AC ✓13ms4412kbC++171.4kb2023-09-05 15:45:482023-09-05 15:45:48

Judging History

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

  • [2023-09-05 15:45:48]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:4412kb
  • [2023-09-05 15:45:48]
  • 提交

answer

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int MAX = 1 << 17;

int deg[MAX], vertices[MAX];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	while (m--) {
		int u, v;
		cin >> u >> v;
		deg[u]++;
		deg[v]++;
	}
	iota(vertices, vertices + n, 0);
	sort(vertices, vertices + n, [](int u, int v){return deg[u] < deg[v];});
	int k = 0, sum = 0, last = n - 1;
	FOR(i, 0, n) {
		sum += deg[vertices[i]];
		if (sum + n - i - 1 <= 2 * (n - 1)) {
			k = i + 1;
			last = 2 * (n - 1) - (sum + n - i - 2);
		}
	}
	FOR(i, k, n - 1) {
		deg[vertices[i]] = 1;
	}
	if (k < n) {
		deg[vertices[n - 1]] = last;
	}
	set<pair<int, int>> s;
	FOR(i, 0, n) {
		s.emplace(deg[i], i);
	}
	cout << n - k << "\n" << n << " " << n - 1 << "\n";
	while (SZ(s) > 1) {
		auto [deg1, v1] = *s.begin();
		s.erase(s.begin());
		auto [deg2, v2] = *prev(s.end());
		s.erase(prev(s.end()));
		assert(deg1 == 1);
		cout << v1 << " " << v2 << "\n";
		s.emplace(deg2 - 1, v2);
	}
}



詳細信息

Test #1:

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

Test #2:

score: 0
Accepted
time: 1ms
memory: 3560kb

Test #3:

score: 0
Accepted
time: 1ms
memory: 3608kb

Test #4:

score: 0
Accepted
time: 1ms
memory: 3876kb

Test #5:

score: 0
Accepted
time: 1ms
memory: 3860kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 3512kb

Test #7:

score: 0
Accepted
time: 1ms
memory: 3668kb

Test #8:

score: 0
Accepted
time: 1ms
memory: 3572kb

Test #9:

score: 0
Accepted
time: 1ms
memory: 3608kb

Test #10:

score: 0
Accepted
time: 1ms
memory: 3608kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 3836kb

Test #12:

score: 0
Accepted
time: 2ms
memory: 3864kb

Test #13:

score: 0
Accepted
time: 1ms
memory: 3572kb

Test #14:

score: 0
Accepted
time: 1ms
memory: 3668kb

Test #15:

score: 0
Accepted
time: 1ms
memory: 3684kb

Test #16:

score: 0
Accepted
time: 1ms
memory: 3884kb

Test #17:

score: 0
Accepted
time: 2ms
memory: 3628kb

Test #18:

score: 0
Accepted
time: 9ms
memory: 3724kb

Test #19:

score: 0
Accepted
time: 2ms
memory: 4156kb

Test #20:

score: 0
Accepted
time: 5ms
memory: 4404kb

Test #21:

score: 0
Accepted
time: 3ms
memory: 4148kb

Test #22:

score: 0
Accepted
time: 6ms
memory: 4208kb

Test #23:

score: 0
Accepted
time: 8ms
memory: 4336kb

Test #24:

score: 0
Accepted
time: 9ms
memory: 4408kb

Test #25:

score: 0
Accepted
time: 10ms
memory: 4080kb

Test #26:

score: 0
Accepted
time: 11ms
memory: 4208kb

Test #27:

score: 0
Accepted
time: 12ms
memory: 4152kb

Test #28:

score: 0
Accepted
time: 13ms
memory: 4180kb

Test #29:

score: 0
Accepted
time: 13ms
memory: 4412kb

Test #30:

score: 0
Accepted
time: 1ms
memory: 3852kb

Test #31:

score: 0
Accepted
time: 1ms
memory: 3632kb

Test #32:

score: 0
Accepted
time: 1ms
memory: 3824kb

Test #33:

score: 0
Accepted
time: 7ms
memory: 3632kb

Test #34:

score: 0
Accepted
time: 1ms
memory: 3828kb

Test #35:

score: 0
Accepted
time: 1ms
memory: 3820kb

Test #36:

score: 0
Accepted
time: 0ms
memory: 3600kb

Test #37:

score: 0
Accepted
time: 1ms
memory: 3820kb