QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#118118#6560. Broken Minimum Spanning Treecada_dia_mas_insanosWA 1ms5580kbC++172.9kb2023-07-03 08:49:392023-07-03 08:49:42

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:49:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5580kb
  • [2023-07-03 08:49:39]
  • 提交

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;
	}
};
const int maxn = 2010, oo = 2e9;
int graph[maxn][maxn], id[maxn][maxn];
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;
	forn(i, n) forn(j, n) graph[i][j] = oo;
	vector <pp> edges;
	forn(i, m) {
		int u, v, w; cin >> u >> v >> w;
		u--, v--;
		graph[u][v] = graph[v][u] = min(w, graph[u][v]);
		if (graph[u][v] == w) id[u][v] = id[v][u] = i;
	}
	forn(i, n) fore(j, i+1, n-1) {
		if (graph[i][j] < oo) {
			edges.pb(mp(mp(graph[i][j], id[i][j]), mp(i, j)));
		}
	}
	m = edges.size();
	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;
}

詳細信息

Test #1:

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

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: 0ms
memory: 5580kb

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!