QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527753#7118. Closing Timegreen_gold_dog#9 943ms26396kbC++202.7kb2024-08-22 19:04:182024-08-22 19:04:18

Judging History

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

  • [2024-08-22 19:04:18]
  • 评测
  • 测评结果:9
  • 用时:943ms
  • 内存:26396kb
  • [2024-08-22 19:04:18]
  • 提交

answer

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

using namespace std;

typedef long long ll;

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

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;
}

void dfs(ll v, vector<bool>& can, vector<bool>& used, vector<vector<pair<ll, ll>>>& arr) {
	if (!can[v]) {
		return;
	}
	used[v] = true;
	for (auto[i, _] : arr[v]) {
		if (!used[i]) {
			dfs(i, can, used, arr);
		}
	}
}

int max_score(int n, int x, int y, long long k, vector<int> u, vector<int> v, vector<int> 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<vector<bool>> cm1, cm2;
	for (ll i = 0; i < (1 << n); i++) {
		vector<bool> can(n, false);
		for (ll j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				can[j] = true;
			}
		}
		vector<bool> used1(n, false), used2(n, false);
		dfs(x, can, used1, arr);
		dfs(y, can, used2, arr);
		if (can == used1) {
			cm1.push_back(can);
		}
		if (can == used2) {
			cm2.push_back(can);
		}
	}
	ll bans = 0;
	for (auto i : cm1) {
		for (auto j : cm2) {
			long long nc = 0;
			ll nans = 0;
			for (ll k = 0; k < n; k++) {
				if (i[k] && j[k]) {
					nc += max(d1[k], d2[k]);
					nans += 2;
				} else {
					if (i[k]) {
						nc += d1[k];
						nans++;
					}
					if (j[k]) {
						nc += d2[k];
						nans++;
					}
				}
			}
			if (nc <= k) {
				if (bans < nans) {
					bans = nans;
				}
			}
		}
	}
	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: 87ms
memory: 26396kb

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
0

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 42ms
memory: 3860kb

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
0

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 9
Accepted

Test #36:

score: 9
Accepted
time: 0ms
memory: 4092kb

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

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: 9
Accepted
time: 1ms
memory: 4088kb

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
Accepted
time: 159ms
memory: 3948kb

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
14

result:

ok 

Test #40:

score: 9
Accepted
time: 943ms
memory: 4084kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
19 3 9 11232111
13 14 174955
0 13 69982
10 14 209946
14 15 209946
12 14 104973
0 11 314919
0 3 314919
0 7 139964
5 10 209946
10 16 69982
4 10 104973
9 11 279928
9 17 349910
1 4 104973
3 18 209946
6 18 174955
7 8 314919
2 7 104973

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
28

result:

ok 

Test #41:

score: 9
Accepted
time: 12ms
memory: 3780kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
15 5 7 155966
1 4 964448
5 11 996819
9 10 330180
5 6 987448
11 12 704605
0 5 155967
8 14 596631
10 11 923917
0 14 560902
4 13 49411
1 7 856694
1 12 755799
2 14 488208
3 13 990480

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
2

result:

ok 

Test #42:

score: 9
Accepted
time: 302ms
memory: 3924kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
20 4 7 40726445
15 18 841797
9 16 909512
0 7 39919
8 19 78725
6 17 661904
7 14 426400
17 18 664669
7 13 917960
4 14 821652
4 11 274656
1 12 937782
10 19 129031
12 13 504353
5 11 502915
3 8 264525
2 19 358409
12 18 578659
16 19 696491
3 17 175157

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
30

result:

ok 

Test #43:

score: 9
Accepted
time: 262ms
memory: 3976kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
19 1 8 758761123780644886
3 18 947982
12 13 415218
3 15 890432
11 17 808801
2 8 726510
7 12 752493
8 17 328133
6 7 465830
8 14 126540
9 18 443041
1 7 605214
4 11 243452
9 10 106626
3 7 498126
1 4 39081
0 2 861168
5 15 69635
3 16 223395

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
38

result:

ok 

Test #44:

score: 9
Accepted
time: 54ms
memory: 3844kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 4 10 8410500
14 16 912609
2 8 546082
2 12 129063
1 17 454917
15 17 85372
1 11 862697
4 11 428830
7 9 860609
8 10 119165
6 11 143393
14 17 789886
13 15 216341
4 5 56300
12 13 718046
0 7 354300
9 15 142154
1 3 310843

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
11

result:

ok 

Test #45:

score: 9
Accepted
time: 123ms
memory: 3920kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 14 15 23103649
0 6 382587
2 4 23201
2 3 58517
0 10 982598
0 17 283539
13 14 944945
4 6 576463
8 14 941541
7 16 566937
1 11 185982
3 9 360540
1 5 441702
4 16 808047
3 14 154737
3 15 344378
9 11 631318
7 12 552451

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
36

result:

ok 

Test #46:

score: 9
Accepted
time: 116ms
memory: 3968kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 7 13 25604
13 17 12802
5 14 39262
6 8 774165
2 11 834406
5 6 1
0 16 432886
3 6 1
2 14 272481
5 12 817066
4 9 40750
15 17 889075
1 7 12804
4 16 406687
5 17 1
3 10 875945
0 1 525803
1 3 1

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
3

result:

ok 

Test #47:

score: 9
Accepted
time: 285ms
memory: 4216kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
19 0 8 951764
0 1 4
1 2 4
2 3 4
3 4 307858
4 5 307858
5 6 4
6 7 4
7 8 4
4 9 121363
7 10 4
8 11 214606
5 12 999998
6 13 1000000
1 14 999995
10 15 999997
1 16 999994
13 17 999996
3 18 999991

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
13

result:

ok 

Test #48:

score: 9
Accepted
time: 748ms
memory: 4340kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
20 0 8 274829
0 1 2
1 2 2
2 3 2
3 4 2
4 5 2
5 6 2
6 7 2
7 8 2
4 9 548538
7 10 2
8 11 274686
6 12 999999
0 13 999995
6 14 999992
9 15 1000000
0 16 999997
9 17 999996
3 18 999998
0 19 999999

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
21

result:

ok 

Test #49:

score: 9
Accepted
time: 70ms
memory: 4204kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 6 13 58800010
7 11 555657
5 9 283104
0 16 323027
5 11 296013
9 15 584423
1 12 410839
7 13 314886
3 14 890353
4 12 174300
3 12 791983
2 5 216145
4 17 259612
3 16 732206
10 11 976379
8 16 650154
4 9 76441
6 8 589585

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
35

result:

ok 

Test #50:

score: 9
Accepted
time: 51ms
memory: 3820kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 5 10 24497819
9 15 154130
7 11 597308
2 11 617436
0 13 517318
3 16 400080
1 5 908978
1 8 181237
4 7 84199
3 6 758216
6 14 32279
11 17 498893
10 12 629338
2 15 180470
10 17 803430
13 16 226223
8 11 134253
4 13 618500

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
26

result:

ok 

Test #51:

score: 9
Accepted
time: 277ms
memory: 3924kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
20 13 17 8319375
13 14 4930
14 18 19720
6 18 104023
1 15 9367
1 19 37961
10 19 1479
14 17 90219
1 11 41905
8 17 986
2 17 4437
8 12 3451
7 12 1479
12 16 3451
3 11 4930
3 5 3944
3 4 4930
0 4 3944
6 15 473280
9 15 4437

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
39

result:

ok 

Test #52:

score: 9
Accepted
time: 167ms
memory: 3928kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
20 6 9 7859406
6 10 3451
4 10 125222
4 7 42891
5 8 17748
3 5 34510
1 3 4930
9 10 69020
5 12 78880
9 11 986
11 16 1972
2 12 1972
0 2 493
0 19 986
18 19 2958
8 15 77894
14 15 77894
13 14 77894
14 17 2958
7 13 77894

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
39

result:

ok 

Test #53:

score: 9
Accepted
time: 209ms
memory: 3984kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 9 14 2009
9 17 245
11 17 549633
10 11 419146
10 13 294
0 13 675465
0 4 743232
4 15 245
14 17 147
3 17 490
2 17 392
5 14 294
6 14 98
3 16 49
0 7 294
1 7 343
7 8 98
7 12 98

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
10

result:

ok 

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%