QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118117#6560. Broken Minimum Spanning Treecada_dia_mas_insanosWA 1ms3408kbC++172.5kb2023-07-03 08:42:382023-07-03 08:42:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 08:42:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3408kb
  • [2023-07-03 08:42:38]
  • 提交

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<pll, pll>;
struct DSU {
	int n;
	vi f, s;
	DSU (int n): n(n) { 
		f.resize(n); iota(ALL(f), 0);
		s.assign(n, 1);
	}
	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(m);
	forn(i, m) {
		int u, v, w; cin >> u >> v >> w;
		u--, v--;
		edges[i] = mp(mp(w, i), mp(u, v));
	}
	sort(ALL(edges));
	DSU mst(n);
	ll w = 0;
	forn(i, m) {
		int u = edges[i].se.fi, v = edges[i].se.se;
		int c = edges[i].fi.fi;
		if (mst.find(u) == mst.find(v)) continue;
		w += c;
		mst.merge(u, v);
	}

	vector <bool> in(m, 0);
	forn(i, m) {
		DSU dsu(n);
		int u = edges[i].se.fi, v = edges[i].se.se;
		int c = edges[i].fi.fi;
		int k = edges[i].fi.se;
		dsu.merge(u, v);
		ll cur = c;

		forn(j, m) if (i != j) {
			u = edges[j].se.fi, v = edges[j].se.se;
			c = edges[j].fi.fi;
			if (dsu.find(u) == dsu.find(v)) continue;
			cur += c;
			dsu.merge(u, v);
		}
		in[k] = cur == w;
	}
	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, j));
		j++;
	}
	cout << ans.size() << endl;
	for(auto& it : ans) cout << it.fi+1 << ' ' << it.se+1 << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

0

result:

FAIL participant's MST is better than jury!