QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643534#6560. Broken Minimum Spanning Treeenze114514WA 1ms3624kbC++201.3kb2024-10-15 21:39:312024-10-15 21:39:34

Judging History

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

  • [2024-10-15 21:39:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-10-15 21:39:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back

const ld pi = 3.14159265358979323846;
// const int mod = 998244353;
const ll INF = 1e18;

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}

template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

const int N = (int)2e5 + 1, M = N * 2;

void solve(){
    int n, m;
    cin >> n >> m;

    vector<vector<int>> a, b, c;

    for(int i = 0; i < m; i++){
        int u, v, w;
        cin >> u >> v >> w;

        if(i < n - 1){
            a.pb({w, u, v, i + 1});
        }
        else{
            b.pb({w, u, v, i + 1});
        }
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    for(int i = n - 2, j = 0; i >= 0 && j < b.size(); ){
        if(a[i][0] > b[j][0]){
            c.pb({a[i][3], b[j][3]});
            j++;
        }
        else{
            i--;
        }
    }

    cout << c.size() << endl;
    for(auto p : c){
        cout << p[0] << " " << p[1] << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
//    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

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: 3624kb

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:

2
5 7
5 8

result:

wrong answer not a spanning tree after swap 1