QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359562#6560. Broken Minimum Spanning TreeLaStataleBlue#RE 0ms0kbC++231.9kb2024-03-20 19:03:332024-03-20 19:03:33

Judging History

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

  • [2024-03-20 19:03:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-20 19:03:33]
  • 提交

answer

#pragma ide diagnostic ignored "misc-no-recursion"

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef long double db;

#define TESTCASE 0

static constexpr int MOD = 998'244'353;
static constexpr int INF = 1.1e9;
static constexpr int MAX_N = 4000;
static constexpr db EPS = 1e-9;

static vector<tuple<int, int, int>> graph[MAX_N];
static bool taken[MAX_N];

static pair<int, int> dfs(int u, int p, int z) {
    for (auto [v, w, i]: graph[u]) {
        if (i == p || !taken[i]) continue;
        if (v == z) return {i, w};
        auto [ri, rw] = dfs(v, u, z);
        if (ri != -1) return rw > w ? pair(ri, rw) : pair(i, w);
    }
    return {-1, -1};
}

static void solve([[maybe_unused]] int tc) {
    ll N, M;
    cin >> N >> M;

    vector<tuple<int, int, int, int>> edges(M);
    int c = 0;
    for (auto &[u, v, w, i]: edges) {
        i = c++;
        cin >> u >> v >> w;
        graph[u].emplace_back(v, w, i);
        graph[v].emplace_back(u, w, i);
        taken[i] = i < N - 1;
    }

    sort(edges.begin(), edges.end(), [&](const auto &a, const auto &b) {
        return get<2>(a) < get<2>(b);
    });

    vector<pair<int, int>> moves;
    for (auto [u, v, w, i]: edges) {
        if (taken[i]) continue;

        auto [ri, rw] = dfs(u, i, v);
        if (ri != -1 && rw > w) {
            moves.emplace_back(ri, i);
            taken[ri] = false;
            taken[i] = true;
        }
    }

    cout << moves.size() << '\n';
    for (auto [a, b]: moves) {
        cout << (a + 1) << ' ' << (b + 1) << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);

    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }

    int T = 1;
#if TESTCASE
    cin >> T;
#endif

    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

4 4
1 2 10
2 3 3
3 4 1
1 4 4

output:


result: