QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643534 | #6560. Broken Minimum Spanning Tree | enze114514 | WA | 1ms | 3624kb | C++20 | 1.3kb | 2024-10-15 21:39:31 | 2024-10-15 21:39:34 |
Judging History
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;
}
詳細信息
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