QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#216743 | #2437. Wireless is the New Fiber | Swarthmore# | AC ✓ | 13ms | 4444kb | C++17 | 1.6kb | 2023-10-15 22:00:25 | 2023-10-15 22:00:26 |
Judging History
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;
}
Details
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