QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#309361#8136. Rebellious Edgeucup-team1303#RE 0ms7764kbC++202.8kb2024-01-20 16:53:552024-01-20 16:53:55

Judging History

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

  • [2024-01-20 16:53:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:7764kb
  • [2024-01-20 16:53:55]
  • 提交

answer

#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
const int N = 2e5 + 10;
namespace priorityqueue {
	int tot, ls[N], rs[N], dist[N], sz[N], tag[N];
	pair <int, int> val[N];
	void down(int num, int x) {
		val[num].first += x;
		tag[num] += x;
	}
	void pushdown(int x) {
		if (tag[x]) {
			down(ls[x], tag[x]); down(rs[x], tag[x]);
			tag[x] = 0;
		}
	}
	int merge(int x, int y) {
		if (!x || !y) return x | y;
		assert(x != y);
		pushdown(x); pushdown(y);
		if (val[x] > val[y]) swap(x, y);
		rs[x] = merge(rs[x], y);
		if (dist[rs[x]] > dist[ls[x]]) swap(ls[x], rs[x]);
		return sz[x] = sz[ls[x]] + sz[rs[x]] + 1, dist[x] = dist[rs[x]] + 1, x;
	}
	struct priorityqueue {
		int rt;
		priorityqueue() { rt = 0; }
		void join(priorityqueue &x) { rt = merge(rt, x.rt); x.rt = 0; }
		void push(pair <int, int> x) { val[++tot] = x, sz[tot] = 1; rt = merge(rt, tot); }
		void pop() { assert(sz[rt]); pushdown(rt); rt = merge(ls[rt], rs[rt]); }
		pair <int, int> top() { assert(sz[rt]); return val[rt]; }
		int size() { return sz[rt]; }
		bool empty() { return !size(); }
		void clear() { rt = 0; }
		void add(int x) { down(rt, x); }
	};
}
priorityqueue::priorityqueue q[N];
int sz, n, m, r, s[N], fa[N];
bool vis[N], out[N];
ll ans;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
bool solve(int x) {
	s[++sz] = x;
	while (!vis[s[sz]] || out[s[sz]]) {
		int x = s[sz];
		if (out[x]) {
			do {
				int y = s[sz--];
				q[y].add(-q[y].top().first);
				if (y != x) fa[y] = x, q[x].join(q[y]), out[y] = false;
			} while (s[sz] != x);
		}
		vis[x] = out[x] = true;
		while (q[x].size() && find(q[x].top().second) == x) q[x].pop();
		if (q[x].empty()) return false;
		ans += q[x].top().first;
		s[++sz] = find(q[x].top().second);
	}
	while (sz) out[s[sz--]] = false;
	return true;
}
void zhk() {
	read(n); read(m); r = 1;
	ans = sz = 0;
	F(i, 1, n) fa[i] = i, q[i].clear(), vis[i] = out[i] = false;
	vis[r] = true;
	F(i, 1, m) {
		int x, y, z; read(x); read(y); read(z);
		q[y].push(make_pair(z, x));
	}
	F(i, 1, n)
		if (!solve(i)) assert(false);
	cout << ans << '\n';
}
signed main() {
	int _; read(_);
	while (_--) zhk();
	return 0;
}

详细

Test #1:

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

input:

3
5 6
1 2 4
1 3 2
2 3 0
3 4 1
4 5 1
5 2 1
4 4
1 2 4
1 3 6
1 4 8
4 2 1000000
3 3
1 2 100
2 1 10
2 3 1000

output:

5
18
1100

result:

ok 3 number(s): "5 18 1100"

Test #2:

score: -100
Runtime Error

input:

50000
4 5
2 4 998973548
2 3 501271695
4 1 778395982
1 4 32454891
1 2 757288934
4 5
1 4 720856669
2 3 665098951
3 4 407461517
2 1 866914401
1 2 457859826
4 5
1 2 75288664
1 4 624893594
3 2 458973866
2 4 769074655
2 3 834773751
4 5
2 3 237060634
2 4 297307882
3 4 200383586
1 2 42856502
3 1 16574713
4 ...

output:

1291015520
1530420294
1534956009
480300722
1366795927
1541095843
2493849488
858095911
1034153425
793861088
605832428
1051598350
612891589
1265994009
517769091
1678219738
1556463491
93634961
960978736
984886788
1696503797
1002892611
1969660290
1431417780
1515267731
977157479
1937478556
654475526
1401...

result: