QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359482#6560. Broken Minimum Spanning TreeLaStataleBlue#WA 0ms3896kbC++231.8kb2024-03-20 18:21:102024-03-20 18:21:10

Judging History

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

  • [2024-03-20 18:21:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3896kb
  • [2024-03-20 18:21:10]
  • 提交

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 tuple<int, int, int> edges[MAX_N];
static vector<tuple<int, int, int>> graph[MAX_N];
static bool taken[MAX_N];

static int W(int i) {
    return get<2>(edges[i]);
}

static int dfs(int u, int p, int z) {
    for (auto [v, w, i]: graph[u]) {
        if (v == p) continue;
        if (v == z) return i;
        int r = dfs(v, u, z);
        if (r != -1) return W(r) > w ? r : i;
    }
    return -1;
}

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

    for (int i = 0; i < M; i++) {
        auto &[u, v, w] = edges[i];
        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, edges + M, [&](const auto& a, const auto& b) {
        return get<2>(a) < get<2>(b);
    });

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

        int r = dfs(u, v, v);
        if (r != -1 && W(r) > w) {
            moves.emplace_back(r, i);
            taken[r] = false;
        }
    }

    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
Wrong Answer
time: 0ms
memory: 3896kb

input:

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

output:

0

result:

FAIL participant's MST is better than jury!