QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292361#7118. Closing TimeFeet_McYeet8 91ms38328kbC++173.5kb2023-12-28 02:15:142024-04-28 08:02:27

Judging History

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

  • [2024-04-28 08:02:27]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:91ms
  • 内存:38328kb
  • [2023-12-28 02:15:16]
  • 评测
  • 测评结果:8
  • 用时:141ms
  • 内存:38536kb
  • [2023-12-28 02:15:14]
  • 提交

answer

// #include "closing.h"
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx2")
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define el << '\n'
#define nl cout << '\n'
#define spc << ' '
#define forn(i,n) for (int i=0; i<n; i++)
#define forl(i,s,e) for (int i=s; i<e; i++)
#define pb push_back
#define fi first
#define se second
#define rsz resize
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
const int inf = 1000000000;
const ll inf2 = 4000000000000000000;

const int MAXN = 200005;
vector<pii> adj[MAXN];
pll dis[MAXN];

int nc(int N, int X, int Y, ll K) {
	bool u[N];
	forn(i,N) u[i] = false;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	pq.push({0,X});
	pq.push({0,Y});
	int tot = 0;
	while (sz(pq)) {
		auto cn = pq.top();
		pq.pop();
		if (cn.fi > K) break;
		if (u[cn.se]) continue;
		K -= cn.fi;
		tot++;
		u[cn.se] = true;
		for (pii i : adj[cn.se]) {
			if (!u[i.fi]) pq.push({cn.fi + i.se, i.fi});
		}
	}
	return tot;
}

vector<int> fp;
vector<int> anc;

void dfs(int cn, int pn, int tn) {
	anc.pb(cn);
	if (cn == tn) {
		for (int i : anc) fp.pb(i);
	}
	for (pii i : adj[cn]) {
		if (i.fi != pn) dfs(i.fi, cn, tn);
	}
	anc.pop_back();
}

int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
	forn(i,N) adj[i].clear();
	fp.clear();
	anc.clear();
	struct st {
		int cn, pn; ll d; bool p;
	};
	forn(i,N-1) {
		adj[U[i]].pb({V[i], W[i]});
		adj[V[i]].pb({U[i], W[i]});
	}
	int ans = nc(N, X, Y, K);
	vector<st> stk;
	stk.pb({X, -1, 0, 0});
	while (sz(stk)) {
		st a = stk.back();
		stk.pop_back();
		if (a.p) dis[a.cn].se = a.d;
		else dis[a.cn].fi = a.d;
		for (pii i : adj[a.cn]) if (i.fi != a.pn) stk.pb({i.fi, a.cn, a.d+i.se, a.p});
	}
	stk.pb({Y, -1, 0, 1});
	while (sz(stk)) {
		st a = stk.back();
		stk.pop_back();
		if (a.p) dis[a.cn].se = a.d;
		else dis[a.cn].fi = a.d;
		for (pii i : adj[a.cn]) if (i.fi != a.pn) stk.pb({i.fi, a.cn, a.d+i.se, a.p});
	}
	forn(i,N) if (dis[i].fi < dis[i].se) swap(dis[i].fi, dis[i].se);
	dfs(X, -1, Y);
	int ans2 = 0;
	for (int i : fp) {
		K -= dis[i].se;
		ans2++;
		dis[i].se = dis[i].fi - dis[i].se;
		dis[i].fi = inf2;
	}
	if (K<0) return ans;
	int ans3 = 0;
	sort(dis,dis+N);
	// forn(i,N) cout << dis[i].fi spc << dis[i].se el;
	// nl;
	int cv = 0;
	ll la = K;
	ll cs = 0;
	set<pair<ll, int>> cu;
	set<pair<ll, int>> ca;
	forn(i,N) ca.insert({dis[i].se, i});
	while (1) {
		if (!sz(ca)) break;
		auto temp = *ca.begin();
		if (cs + temp.fi > la) break;
		cv++;
		cs += temp.fi;
		cu.insert(temp);
		ca.erase(temp);
	}
	ans3 = cv;
	ll rs = 0;
	forn(i,N) {
		if (cu.find({dis[i].se, i}) == cu.end()) ca.erase({dis[i].se, i});
		else {
			cu.erase({dis[i].se, i});
			cv--;
			cs -= dis[i].se;
		}
		if (i) {
			cu.insert({dis[i-1].fi - dis[i-1].se, i-1});
			cs += dis[i-1].fi;
			cv++;
		}
		if (rs + dis[i].fi > K) break;
		la = K - dis[i].fi;
		while (cs > la) {
			if (!sz(cu)) break;
			auto temp = *(--cu.end());
			cu.erase(temp);
			ca.insert(temp);
			cs -= temp.fi;
			cv--;
		}
		while (1) {
			if (!sz(ca)) break;
			auto temp = *(ca.begin());
			if (cs + temp.fi > la) break;
			cs += temp.fi;
			ca.erase(temp);
			cu.insert(temp);
			cv++;
		}
		if (cs > la) break;
		ans3 = max(ans3, cv + 2);
		rs += dis[i].se;
	}
	// cout << ans spc << ans2 spc << ans3 el;
	return max(ans, ans2+ans3);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 77ms
memory: 30540kb

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
451

result:

ok 

Test #2:

score: 0
Accepted
time: 91ms
memory: 38328kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 97133 170892 35489415917
114511 170892 730058
34783 114511 435023
34783 47301 562314
47301 162600 457629
44856 162600 365133
44856 133801 83016
117539 133801 124222
117539 128719 199821
77871 128719 703141
77871 133155 624331
7211 133155 138691
7211 ...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
650

result:

ok 

Test #3:

score: 0
Accepted
time: 35ms
memory: 12404kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
200
1000 611 992 5736784
504 611 954658
504 936 219278
502 936 632439
393 502 177662
267 393 570266
267 291 941365
291 310 168052
310 765 253098
635 765 724932
274 635 842125
274 799 848645
39 799 433118
39 940 705598
553 940 564063
553 960 69665
917 960 6904...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
126
38
69
34
52
33
42
32
39
41
38
36
45
84
40
44
50
42
47
34
38
47
38
37
39
37
44
39
32
33
38
54
25
36
46
33
37
35
28
36
45
43
44
49
37
33
43
44
53
42
33
30
50
41
37
40
37
44
207
31
37
45
36
43
35
40
41
39
135
53
40
32
31
37
34
38
51
48
36
40
48
42
43
43
3...

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 8748kb

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
54

result:

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

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: 9
Accepted
time: 0ms
memory: 9608kb

input:

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

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
6

result:

ok 

Test #37:

score: 0
Accepted
time: 2ms
memory: 9748kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 8
0 2 2
1 2 3
2 3 100

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
5

result:

ok 

Test #38:

score: 0
Accepted
time: 0ms
memory: 9808kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
8 0 4 84
0 1 1
1 2 29
2 3 29
3 4 1
4 5 20
2 6 20
3 7 1

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
9

result:

ok 

Test #39:

score: -9
Wrong Answer
time: 2ms
memory: 9324kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 14 15 221112
8 10 15984
3 8 2664
6 10 5328
9 10 13320
5 10 23976
1 10 13320
3 4 5328
3 7 26640
3 11 23976
4 15 23976
6 17 18648
12 17 5328
11 13 13320
0 11 7992
15 16 5328
2 16 5328
13 14 2664

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
13

result:

wrong answer 1st lines differ - on the 1st token, expected: '14', found: '13'

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:

100%
Accepted

Dependency #2:

0%