QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#216743#2437. Wireless is the New FiberSwarthmore#AC ✓13ms4444kbC++171.6kb2023-10-15 22:00:252023-10-15 22:00:26

Judging History

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

  • [2023-10-15 22:00:26]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:4444kb
  • [2023-10-15 22:00:25]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

void solve() {
	int N, M; cin >> N >> M;
	vpi deg(N); F0R(i, N) deg[i].s = i;
	F0R(i, M) {
		int X, Y; cin >> X >> Y; 
		deg[X].f++; deg[Y].f++;
	}
	sort(all(deg));
	int tot = 0;
	int cnt = N;
	F0R(i, N) {
		tot += deg[i].f;
		if (tot + N-i-1 > 2*N-2) {
			cnt = i;
			break;
		}
	}
	int nd[N]; F0R(i, N) nd[i] = 0;
	bool keep[N]; F0R(i, N) keep[i] = false;
	cout << N - cnt << nl;
	cout << N << " " << N-1 << nl;
	tot = 0;
	F0R(i, cnt) {
		keep[deg[i].s] = true;
		nd[deg[i].s] = deg[i].f;
		tot += deg[i].f;
	}
	int rem = 2*N-2-tot;
	while (rem > 0) {
		F0R(i, N) {
			if (!keep[i] && rem > 0) {
				rem--;
				nd[i]++;
			}
		}
	}
	set<pi> degs;
	F0R(i, N) {
		degs.ins({nd[i], i});
	}
	while (sz(degs) >= 2) {
		pi X = *degs.begin(), Y = *degs.rbegin();
		cout << X.s << " " << Y.s << nl;
		degs.erase(X); degs.erase(Y);
		degs.ins({Y.f-1, Y.s});
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
	return 0;
}

詳細信息

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

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

Test #19:

score: 0
Accepted
time: 4ms
memory: 4372kb

Test #20:

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

Test #21:

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

Test #22:

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

Test #23:

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

Test #24:

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

Test #25:

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

Test #26:

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

Test #27:

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

Test #28:

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

Test #29:

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

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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