QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380780#2437. Wireless is the New Fiber8BQube#AC ✓232ms786276kbC++202.0kb2024-04-07 12:00:062024-04-07 12:00:07

Judging History

This is the latest submission verdict.

  • [2024-04-07 12:00:07]
  • Judged
  • Verdict: AC
  • Time: 232ms
  • Memory: 786276kb
  • [2024-04-07 12:00:06]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())

const int N = 10005;

int dp[N][N], frm[N][N], deg[N], fin[N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    while (m--) {
        int u, v;
        cin >> u >> v;
        ++u, ++v;
        ++deg[u], ++deg[v];
    }
    for (int i = 1; i <= n; ++i) {
        pii mx = pii(-n, 0), smx = pii(-n, 0);
        for (int j = 0; j < n; ++j) {
            dp[i][j] = -n;
            if (dp[i - 1][j] > mx.X)
                smx = mx, mx = pii(dp[i - 1][j], j);
            else if (dp[i - 1][j] > smx.X)
                smx = pii(dp[i - 1][j], j);

            auto check = [&](int k, int v) {
                if (v > dp[i][j]) {
                    dp[i][j] = v;
                    frm[i][j] = k;
                }
            };

            if (deg[i] - 1 <= j) {
                int v = dp[i - 1][j - (deg[i] - 1)];
                check(j - (deg[i] - 1), v + 1);
                if (mx.X == v) check(smx.Y, smx.X);
                else check(mx.Y, mx.X);
            }
            else
                check(mx.Y, mx.X);
        }
    }

    set<pii> st;
    int ans = dp[n][n - 2];
    int cur = n - 2, nw = n;
    while (nw > 0) {
        int nxt = frm[nw][cur];
        fin[nw] = cur - nxt + 1;
        st.insert(pii(fin[nw], nw));
        cur = nxt, --nw;
    }

    vector<pii> edge;
    while (SZ(st) > 1) {
        int a = st.begin()->Y;
        st.erase(st.begin());
        int b = st.rbegin()->Y;
        st.erase(--st.end());
        edge.pb(pii(a, b));
        --fin[a], --fin[b];
        if (fin[a] > 0) st.insert(pii(fin[a], a));
        if (fin[b] > 0) st.insert(pii(fin[b], b));
    }

    cout << n - ans << "\n";
    cout << n << " " << n - 1 << "\n";
    for (auto [u, v] : edge)
        cout << u - 1 << " " << v - 1 << "\n";
}

Details

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

score: 0
Accepted
time: 9ms
memory: 83692kb

Test #18:

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

Test #19:

score: 0
Accepted
time: 204ms
memory: 785936kb

Test #20:

score: 0
Accepted
time: 217ms
memory: 786240kb

Test #21:

score: 0
Accepted
time: 215ms
memory: 785992kb

Test #22:

score: 0
Accepted
time: 221ms
memory: 785936kb

Test #23:

score: 0
Accepted
time: 220ms
memory: 785852kb

Test #24:

score: 0
Accepted
time: 196ms
memory: 786276kb

Test #25:

score: 0
Accepted
time: 232ms
memory: 785884kb

Test #26:

score: 0
Accepted
time: 210ms
memory: 785784kb

Test #27:

score: 0
Accepted
time: 225ms
memory: 785764kb

Test #28:

score: 0
Accepted
time: 210ms
memory: 785692kb

Test #29:

score: 0
Accepted
time: 226ms
memory: 786244kb

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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