QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357055#2437. Wireless is the New FiberSorting#AC ✓13ms4452kbC++201.5kb2024-03-18 17:50:072024-03-18 17:50:08

Judging History

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

  • [2024-03-18 17:50:08]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:4452kb
  • [2024-03-18 17:50:07]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()

const int N = 1e5 + 3;

int d[N], n, m;
int new_d[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= m; ++i){
        int u, v;
        cin >> u >> v;
        ++d[u];
        ++d[v];
    }

    vector<pair<int, int>> v;
    for(int i = 0; i < n; ++i){
        v.push_back({d[i], i});
    }

    sort(all(v));

    int sum = 0, ans = 0;
    for(int i = 0; i < n; ++i){
        if(sum + v[i].first + n - i - 1 > 2 * (n - 1)){
            ans = n - i;
            for(; i < n - 1; ++i){
                new_d[v[i].second] = 1;
                ++sum;
            }
            new_d[v.back().second] = 2 * (n - 1) - sum;
            break; 
        }

        new_d[v[i].second] = v[i].first;
        sum += v[i].first;
    }

    set<pair<int, int>> s;
    for(int i = 0; i < n; ++i){
        s.insert({new_d[i], i});
    }

    cout << ans << "\n";
    cout << n << " " << n - 1 << endl;
    for(int i = 0; i < n - 1; ++i){
        // cout << s.size() << " s size " << i << endl;
        auto [du, u] = *s.begin();
        s.erase(s.begin());

        auto [dv, v] = *s.rbegin();
        s.erase({dv, v});

        --dv;
        cout << v << " " << u << "\n";
        if(dv){
            s.insert({dv, v});
        }
    }
}

詳細信息

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

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

Test #19:

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

Test #20:

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

Test #21:

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

Test #22:

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

Test #23:

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

Test #24:

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

Test #25:

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

Test #26:

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

Test #27:

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

Test #28:

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

Test #29:

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

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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