QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165067 | #2437. Wireless is the New Fiber | PetroTarnavskyi# | AC ✓ | 13ms | 4412kb | C++17 | 1.4kb | 2023-09-05 15:45:48 | 2023-09-05 15:45:48 |
Judging History
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);
}
}
Details
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