QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#131718#2760. Simurghpandapythoner#0 0ms3804kbC++203.9kb2023-07-27 22:14:572024-07-04 01:00:30

Judging History

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

  • [2024-07-04 01:00:30]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3804kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 22:14:57]
  • 提交

answer

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif


#include <bits/stdc++.h>

#include "simurgh.h"

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const ll inf = 1e18;
mt19937 rnd(234);

struct DSU {
    int n;
    vector<int> t;

    void build(int _n) {
        n = _n;
        t.resize(n);
        for (int i = 0; i < n; i += 1) {
            t[i] = i;
        }
    }
};

struct edge {
    int to, i;
};

bool operator==(const edge &a, const edge &b) {
    return a.to == b.to && a.i == b.i;
}

int n, m;
vector<pair<int, int>> edgs;
vector<int> tp;
vector<vector<edge>> g;
vector<int> usd;
vector<int> h;

bool dfs0(int v, int mh, int pri, vector<int> &stck, vector<int> &cycle) {
    h[v] = mh;
    usd[v] = 1;
    for (auto [to, i] : g[v]) {
        if (pri == i) {
            continue;
        }
        if (usd[to] == 1) {
            int dst = mh - h[to];
            cycle = vector<int>(stck.end() - dst, stck.end());
            cycle.push_back(i);
            return true;
        }
        if (usd[to] == 0) {
            stck.push_back(i);
            int x = dfs0(to, mh + 1, i, stck, cycle);
            stck.pop_back();
            if (x) {
                return true;
            }
        }
    }
    usd[v] = 2;
    return false;
}

void find_cycle(vector<int> &cycle) {
    usd.assign(n, 0);
    h.resize(n);
    vector<int> stck;
    stck.reserve(n);
    dfs0(0, 0, -1, stck, cycle);
}

void dfs1(int v, vector<int> &rs) {
    usd[v] = 1;
    for (auto [to, i] : g[v]) {
        if (!usd[to]) {
            rs.push_back(i);
            dfs1(to, rs);
        }
    }
}

vector<int> add_edgs(vector<int> &c) {
    auto rs = c;
    usd.assign(n, 0);
    for (auto i : c) {
        auto [u, v] = edgs[i];
        usd[u] = 1;
        usd[v] = 1;
    }
    for (auto i : c) {
        auto [u, v] = edgs[i];
        dfs1(u, rs);
    }
    return rs;
}

void reveal_cycle(vector<int> &c) {
    auto f = add_edgs(c);
    int sz = (int)c.size();
    vector<int> p(sz, -1);
    int mx = 0;
    for (int i = 0; i < sz; i += 1) {
        int j = c[i];
        if (tp[j] == -1) {
            auto nf = f;
            nf.erase(nf.begin() + i);
            p[i] = count_common_roads(nf);
            mx = max(mx, p[i]);
        }
    }
    for (int i = 0; i < sz; i += 1) {
        int j = c[i];
        if (tp[j] == -1) {
            if (p[i] == mx) {
                tp[j] = 0;
            } else {
                tp[j] = 1;
            }
        }
    }
}

void erase(vector<edge> &t, const edge &x) {
    for (int i = 0; i < (int)t.size(); i += 1) {
        if (t[i] == x) {
            t.erase(t.begin() + i);
            break;
        }
    }
}

void delete_edge_from_g(int i) {
    auto [u, v] = edgs[i];
    erase(g[u], edge{v, i});
    erase(g[v], edge{u, i});
}

vector<int> solve_slow() {
    tp.assign(m, -1);
    g.assign(n, vector<edge>());
    for (int i = 0; i < m; i += 1) {
        auto [u, v] = edgs[i];
        g[u].push_back(edge{v, i});
        g[v].push_back(edge{u, i});
    }
    int cnt = m;
    while (cnt > n - 1) {
        vector<int> c;
        find_cycle(c);
        reveal_cycle(c);
        for (auto j : c) {
            if (tp[j] == 0) {
                delete_edge_from_g(j);
                cnt -= 1;
            }
        }
    }
    vector<int> rs;
    for (int v = 0; v < n; v += 1) {
        for (auto [to, i] : g[v]) {
            if (to < v) {
                rs.push_back(i);
            }
        }
    }
    return rs;
}

vector<int> find_roads(int _n, vector<int> _u, vector<int> _v) {
    n = _n;
    m = _u.size();
    edgs.resize(m);
    for (int i = 0; i < m; i += 1) {
        edgs[i] = make_pair(_u[i], _v[i]);
    }
    auto rs = solve_slow();
    return rs;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3776kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
7 21 30000
2 0
0 1
5 2
2 6
1 3
3 0
6 0
4 5
3 2
4 0
1 4
0 5
4 3
4 6
6 1
2 1
5 3
2 4
5 6
5 1
6 3
7 10 9 13 12 17

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
WA
NO

result:

wrong answer WA in grader: NO

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #58:

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

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
2 1 12000
1 0
0

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
0

result:

ok correct

Test #59:

score: -19
Wrong Answer
time: 0ms
memory: 3804kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
10 45 12000
4 8
0 5
2 0
5 8
8 0
3 8
6 4
4 1
2 3
2 1
6 2
1 7
3 7
8 1
7 0
8 6
0 6
9 5
9 6
7 4
7 6
7 9
1 6
3 5
2 5
7 5
3 9
0 3
3 6
2 9
1 5
0 4
7 8
5 4
9 4
5 6
3 1
2 8
7 2
2 4
1 0
9 8
4 3
1 9
9 0
22 41 3 16 7 25 28 11 39

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
WA
NO

result:

wrong answer WA in grader: NO

Subtask #5:

score: 0
Skipped

Dependency #1:

0%