UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213159#2675. Road ReformraywuCompile Error//C++1.1kb2024-11-09 21:54:112024-11-09 23:23:37

answer

#include <bits/stdc++.h>
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
#define ll long long
using namespace std;
const int N = 2e5 + 5;
int n, m, k, flag, ecnt; ll ans;
struct Edge { int u, v, w; } e[N];
struct DSU {
	int fa[N];
	inline void init() { iota(fa + 1, fa + n + 1, 1); }
	int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
	inline bool check(int u, int v) { return find(u) == find(v); }
	inline void merge(int u, int v) {
		u = find(u), v = find(v);
		if (u ^ v)  fa[u] = v;
	}
} dsu;
int main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> k, dsu.init();
	_for (i, 1, m)  cin >> e[i].u >> e[i].v >> e[i].w;
	sort(e + 1, e + m + 1, [&] (Edge u, Edge v) { return u.w < v.w; });
	_for (i, 1, m)  if (! dsu.check(e[i].u, e[i].v)) {
		dsu.merge(e[i].u, e[i].v), ecnt ++ ;
		if (e[i].w > k)  flag = 1, ans += e[i].w - k;
		if (ecnt == n - 1)  break;
	}
	if (flag)  return cout << ans << "\n", 0;
	ans = (ll)1e18 + 5;
	_for (i, 1, m)  ans = min(ans, 1ll * abs(k - e[i].w));
	return cout << ans << "\n", 0;
}

详细

answer.code: In member function 'void DSU::init()':
answer.code:10:49: error: 'iota' was not declared in this scope
  inline void init() { iota(fa + 1, fa + n + 1, 1); }\x0d
                                                 ^
answer.code: In function 'int main()':
answer.code:22:66: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  sort(e + 1, e + m + 1, [&] (Edge u, Edge v) { return u.w < v.w; });\x0d
                                                     ...