QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359477#6560. Broken Minimum Spanning TreeLaStataleBlue#WA 1ms3828kbC++231.8kb2024-03-20 18:17:342024-03-20 18:17:35

Judging History

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

  • [2024-03-20 18:17:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-03-20 18:17:34]
  • 提交

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);

    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;
            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: 100
Accepted
time: 1ms
memory: 3828kb

input:

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

output:

1
1 4

result:

ok correct!

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3484kb

input:

6 8
1 2 10
2 3 10
3 4 10
4 5 10
5 6 10
6 1 10
1 3 1
4 6 1

output:

1
3 6

result:

FAIL participant's MST is better than jury!