QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#119202 | #6560. Broken Minimum Spanning Tree | tovarisch | WA | 1ms | 3412kb | C++17 | 2.5kb | 2023-07-05 04:12:09 | 2023-07-05 04:12:10 |
Judging History
answer
// Too many mind, no mind.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <iomanip>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define COMP(x) sort(ALL(x)); x.resize(unique(ALL(x)) - (x).begin())
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
using pii = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pii>;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using ld = long double;
using vld = vector<ld>;
using pp = pair<pii, pii>;
struct DSU {
int n;
vi s, f;
DSU (int n): n(n) {
s.assign(n+5, 1);
f.resize(n+5); iota(ALL(f), 0);
}
int find(int a) { return f[a] = f[a] == a ? a : find(f[a]); }
void merge(int a, int b) {
a = find(a), b = find(b);
if (a == b) return;
if (s[a] < s[b]) swap(a, b);
s[a] += s[b];
f[b] = a;
}
};
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m; cin >> n >> m;
vector <pp> edges, tree;
forn(i, n-1) {
int u, v, w; cin >> u >> v >> w;
u--, v--;
tree.pb(mp(mp(w, i), mp(u, v)));
}
fore(i, n-1, m-1) {
int u, v, w; cin >> u >> v >> w;
u--, v--;
edges.pb(mp(mp(w, i), mp(u, v)));
}
sort(ALL(edges));
for(auto& p: edges) {
tree.pb(p);
sort(ALL(tree));
DSU dsu(n);
int out = -1;
for(auto& it : tree) {
int i = it.fi.se;
int u = it.se.fi, v = it.se.se;
if (dsu.find(u) == dsu.find(v)) out = i;
else dsu.merge(u, v);
}
vector <pp> aux;
for(auto& it : tree) {
int i = it.fi.se;
if (i != out) aux.pb(it);
}
tree = aux;
}
vector <bool> in(m);
for(auto& it : tree) {
int i = it.fi.se;
in[i] = 1;
}
vpi ans;
for(int i=0, j=n-1; i < n-1; i++) {
if (in[i]) continue;
while (j < m && !in[j]) j++;
ans.pb(mp(i+1, j+1));
}
cout << ans.size() << endl;
for(auto& it : ans) cout << it.fi << ' ' << it.se << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
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: 3412kb
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 2 7 5 7
result:
wrong answer bad swap 5 7