QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372069#2437. Wireless is the New Fibercciafrino#AC ✓10ms3916kbC++201.2kb2024-03-30 20:56:282024-03-30 20:56:29

Judging History

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

  • [2024-03-30 20:56:29]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:3916kb
  • [2024-03-30 20:56:28]
  • 提交

answer

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

const int maxn = 2e4;
int deg[maxn];
int S, cnd;
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int N, M; cin >> N >> M;

    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        deg[a] += 1;
        deg[b] += 1;
    }

    for (int x = 0; x < N; ++x) deg[x]--;

    vector<int> ids(N); iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](const auto& l, const auto& r) {
        return deg[l] < deg[r];
    });

    for (int i = 0; i < N; ++i) {
        if (S + deg[ids[i]] > N-2) break;
        S += deg[ids[i]];
        cnd += 1;
    }

    cout << N-cnd << '\n';
    cout << N << ' '  << N-1 << '\n';

    for (int i = cnd; i < N; ++i) {
        if (S == N-2) deg[ids[i]] = 0;
        else {
            deg[ids[i]] = 1;
            S += 1;
        }
    }

    sort(ids.begin(), ids.end(), [&](const auto& l, const auto& r) {
        return deg[l] < deg[r];
    });

    int j = 0;
    for (int i = 0; i+2 < N; ++i) {
        while (deg[ids[j]] == 0) j += 1;
        deg[ids[j]] -= 1;
        cout << ids[i] << ' ' << ids[j] << '\n';
    }

    cout << ids[N-2] << ' ' << ids[N-1] << '\n';
}

詳細信息

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

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

Test #19:

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

Test #20:

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

Test #21:

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

Test #22:

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

Test #23:

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

Test #24:

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

Test #25:

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

Test #26:

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

Test #27:

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

Test #28:

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

Test #29:

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

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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