QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527512#7118. Closing Timegreen_gold_dog#0 99ms48336kbC++203.5kb2024-08-22 16:22:172024-08-22 16:22:17

Judging History

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

  • [2024-08-22 16:22:17]
  • 评测
  • 测评结果:0
  • 用时:99ms
  • 内存:48336kb
  • [2024-08-22 16:22:17]
  • 提交

answer

#include "closing.h"
#include <bits/stdc++.h>

using namespace std;

typedef int ll;

const long long INF = 1'000'000'000'000'000'000;

vector<long long> dist(ll v, vector<vector<pair<ll, ll>>>& arr) {
	vector<long long> ans(arr.size(), INF);
	ans[v] = 0;
	priority_queue<pair<long long, ll>, vector<pair<long long, ll>>, greater<pair<long long, ll>>> pq;
	pq.emplace(0, v);
	while (!pq.empty()) {
		auto[d, nv] = pq.top();
		pq.pop();
		if (ans[nv] != d) {
			continue;
		}
		for (auto[i, c] : arr[nv]) {
			if (ans[i] > d + c) {
				ans[i] = d + c;
				pq.emplace(d + c, i);
			}
		}
	}
	return ans;
}

bool dfs(ll v, ll p, ll need, vector<vector<pair<ll, ll>>>& arr, vector<ll>& way) {
	way.push_back(v);
	if (v == need) {
		return true;
	}
	for (auto[i, _] : arr[v]) {
		if (i != p) {
			if (dfs(i, v, need, arr, way)) {
				return true;
			}
		}
	}
	way.pop_back();
	return false;
}

ll max_score(ll n, ll x, ll y, long long k, vector<ll> u, vector<ll> v, vector<ll> w) {
	vector<vector<pair<ll, ll>>> arr(n);
	for (ll i = 0; i < n - 1; i++) {
		arr[u[i]].emplace_back(v[i], w[i]);
		arr[v[i]].emplace_back(u[i], w[i]);
	}
	vector<long long> d1 = dist(x, arr), d2 = dist(y, arr);
	vector<ll> way;
	dfs(x, x, y, arr, way);
	vector<bool> inway(n, false);
	for (auto i : way) {
		inway[i] = true;
	}
	vector<tuple<long long, bool, ll>> cost;
	for (ll i = 0; i < n; i++) {
		if (inway[i]) {
			continue;
		}
		if (d1[i] > d2[i]) {
			swap(d1[i], d2[i]);
		}
		d2[i] -= d1[i];
		if (d2[i] < d1[i]) {
			cost.emplace_back(d1[i] + d2[i], true, i);
			cost.emplace_back(d1[i] * 2, false, i);
		} else {
			cost.emplace_back(d1[i] * 2, false, i);
			cost.emplace_back(d2[i] * 2, false, i);
		}
	}
	long long ost = 0;
	ll ans = 0;
	ll l1 = -1;
	vector<bool> b2(n, false);
	sort(cost.begin(), cost.end());
	vector<pair<long long, ll>> a;
	a.emplace_back(0, 0);
	for (auto[c, is2, i] : cost) {
		if (is2) {
			if (l1 >= 0) {
				a.emplace_back(ost - l1 + c, ans + 1);
			}
			ost += c;
			ans += 2;
		} else {
			if (ost >= c / 2) {
				ost -= c / 2;
				ans++;
				l1 = c / 2;
			}
		}
		a.emplace_back(ost, ans);
	}
	sort(a.begin(), a.end());
	ll nb = -1;
	vector<pair<long long, ll>> bas;
	for (ll i = 0; i < a.size(); i++) {
		if (a[i].second >= nb) {
			bas.push_back(a[i]);
			nb = a[i].second;
		}
	}
	ll bans = 0;
	for (ll i = 0; i < way.size(); i++) {
		ll nans = i + 1;
		k -= d1[way[i]];
		ll now = bas.size() - 1;
		long long nowk = k;
		for (ll j = way.size() - 1; j >= 0; j--) {
			nans++;
			nowk -= d2[way[j]];
			if (nowk < 0) {
				break;
			}
			while (bas[now].first > nowk) {
				now--;
			}
			if (bans < nans + bas[now].second) {
				bans = nans + bas[now].second;
			}
		}
	}
	return bans;
}

#ifdef LOCAL
int main()
{

    int Q;
    assert(1 == scanf("%d", &Q));

    std::vector<int> N(Q), X(Q), Y(Q);
    std::vector<long long> K(Q);
    std::vector<std::vector<int>> U(Q), V(Q), W(Q);

    for (int q = 0; q < Q; q++)
    {
        assert(4 == scanf("%d %d %d %lld", &N[q], &X[q], &Y[q], &K[q]));

        U[q].resize(N[q] - 1);
        V[q].resize(N[q] - 1);
        W[q].resize(N[q] - 1);
        for (int i = 0; i < N[q] - 1; ++i)
        {
            assert(3 == scanf("%d %d %d", &U[q][i], &V[q][i], &W[q][i]));
        }
    }
    fclose(stdin);

    std::vector<int> result(Q);
    for (int q = 0; q < Q; q++)
    {
        result[q] = max_score(N[q], X[q], Y[q], K[q], U[q], V[q], W[q]);
    }

    for (int q = 0; q < Q; q++)
    {
        printf("%d\n", result[q]);
    }
    fclose(stdout);

    return 0;
}
#endif

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 99ms
memory: 48336kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
260

result:

wrong answer 1st lines differ - on the 1st token, expected: '451', found: '260'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3844kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
132

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '132'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 0ms
memory: 3832kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
7

result:

wrong answer 1st lines differ - on the 1st token, expected: '6', found: '7'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%