QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372840#2437. Wireless is the New FiberTWTP_TCTF#AC ✓20ms4108kbC++142.0kb2024-03-31 19:48:022024-03-31 19:48:03

Judging History

This is the latest submission verdict.

  • [2024-03-31 19:48:03]
  • Judged
  • Verdict: AC
  • Time: 20ms
  • Memory: 4108kb
  • [2024-03-31 19:48:02]
  • Submitted

answer

#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e4 + 5, mod = 1e9 + 7, A = 26;
int co[N];


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        co[a]++;
        co[b]++;
    }
    deque<pair<int, int>> dq;
    for (int i = 0; i < n; i++)
        dq.push_back({co[i], i});
    sort(dq.begin(), dq.end());
    //v.back().first++;
    vector<pair<int, int>> ans;
    int cobad = 0;
    deque<int> q;
    while (dq.size()) {
        auto it = dq.front();
        dq.pop_front();
        it.first--;
        while (q.size() < it.first && dq.size()) {
            cobad++;
            q.push_back(dq.back().second);
            dq.pop_back();
        }
        if (dq.empty()) {
            if (q.size() != it.first + 1) {
                cobad++;
            }
            while (q.size()) {
                ans.push_back({it.second, q.front()});
                q.pop_front();
            }
            break;
        }

        if (q.size() >= it.first) {
            for (int i = 0; i < it.first; i++) {
                ans.push_back({it.second, q.front()});
                q.pop_front();
            }
            q.push_back(it.second);
        } else {
            cobad++;
            if (q.size() == 0) {
                cobad++;
                for (int i = 0; i < n; i++) {
                    if (i != it.second) {
                        ans.push_back({i, it.second});
                        break;
                    }
                }
            }
            while (q.size()) {
                ans.push_back({it.second, q.front()});
                q.pop_front();
            }
        }
    }
    cout << cobad << "\n";
    cout << n << " " << n - 1 << "\n";
    for (auto it: ans)
        cout << it.first << " " << it.second << "\n";


    return 0;
}

详细

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

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

Test #19:

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

Test #20:

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

Test #21:

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

Test #22:

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

Test #23:

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

Test #24:

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

Test #25:

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

Test #26:

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

Test #27:

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

Test #28:

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

Test #29:

score: 0
Accepted
time: 20ms
memory: 4032kb

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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