QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643629#6560. Broken Minimum Spanning Treeenze114514RE 1ms3808kbC++201.4kb2024-10-15 22:28:142024-10-15 22:28:24

Judging History

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

  • [2024-10-15 22:28:24]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3808kb
  • [2024-10-15 22:28:14]
  • 提交

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());
    map<int, int> mp;

    for(int i = n - 2, j = 0; i >= 0 && j < b.size(); ){
        if(a[i][0] > b[j][0] && mp[i] != 1){
            c.pb({a[i][3], b[j][3]});
            j++;
            mp[i] = 1;
            i = n - 1;
        }
        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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3808kb

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
Runtime Error

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:


result: