UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213264#3849. 旅行日记one_zero_four_zero25384ms11756kbC++11817b2024-11-10 10:24:072024-11-10 13:04:58

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

long long ans = 0;
int N, S, cid = 0;
int u, v;
vector<int> E[100005];
priority_queue<int, vector<int>, greater<int> > q;
int fa[100005];

void erg(int u){
	for (auto && v : E[u]){
		if (v == fa[u]) continue;
		fa[v] = u;
		erg(v);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("../data.in", "r", stdin);
	freopen("../data.out", "w", stdout);
#endif

	scanf("%d %d", &N, &S);
	for (int i = 1; i < N; i ++){
		scanf("%d %d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	erg(S);
	q.push(S);
	while (!q.empty()){
		int u = q.top();
		q.pop();
		cid ++;
		ans += 1LL * u * cid;
		for (auto && v : E[u]){
			if (v == fa[u]) continue;
			q.push(v);
		}
	}
	printf("%lld\n", ans);

	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

10 6
5 8
3 8
9 8
10 3
6 8
7 10
1 7
2 5
4 10

output:

290

result:

wrong answer 1st numbers differ - expected: '304', found: '290'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3588kb

input:

10 7
1 5
10 1
6 5
7 5
4 6
8 6
2 6
3 6
9 1

output:

345

result:

ok 1 number(s): "345"

Test #3:

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

input:

10 9
4 9
8 9
1 8
6 4
5 1
2 4
10 8
3 6
7 3

output:

313

result:

wrong answer 1st numbers differ - expected: '320', found: '313'

Test #4:

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

input:

10 7
6 1
2 1
8 2
4 6
9 2
10 2
7 6
3 10
5 4

output:

328

result:

wrong answer 1st numbers differ - expected: '336', found: '328'

Test #5:

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

input:

18 10
11 16
15 11
5 11
7 16
17 15
13 16
8 13
9 5
12 13
14 8
4 5
18 4
2 4
10 16
3 16
1 10
6 9

output:

1905

result:

wrong answer 1st numbers differ - expected: '1911', found: '1905'

Test #6:

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

input:

18 15
8 16
13 16
7 13
2 13
9 8
5 9
3 13
15 5
1 13
4 3
18 9
14 4
17 2
12 13
10 5
11 1
6 18

output:

1712

result:

wrong answer 1st numbers differ - expected: '1750', found: '1712'

Test #7:

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

input:

18 1
17 9
12 17
3 12
8 9
14 17
15 3
18 15
4 3
11 9
16 3
6 15
2 11
5 8
10 5
1 12
7 5
13 1

output:

1756

result:

wrong answer 1st numbers differ - expected: '1895', found: '1756'

Test #8:

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

input:

18 15
10 11
9 10
16 9
17 10
6 10
12 16
13 11
15 10
8 13
7 8
5 16
4 13
1 15
18 16
14 7
2 18
3 18

output:

1657

result:

wrong answer 1st numbers differ - expected: '1728', found: '1657'

Test #9:

score: 5
Accepted
time: 23ms
memory: 7948kb

input:

100000 16441
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
...

output:

333338198204980

result:

ok 1 number(s): "333338198204980"

Test #10:

score: 5
Accepted
time: 27ms
memory: 7948kb

input:

100000 99177
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
...

output:

333333415360924

result:

ok 1 number(s): "333333415360924"

Test #11:

score: 5
Accepted
time: 16ms
memory: 7948kb

input:

100000 59601
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
...

output:

333336557240200

result:

ok 1 number(s): "333336557240200"

Test #12:

score: 5
Accepted
time: 23ms
memory: 7948kb

input:

100000 30655
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
...

output:

333337863500815

result:

ok 1 number(s): "333337863500815"

Test #13:

score: 0
Wrong Answer
time: 32ms
memory: 11536kb

input:

100000 53503
15420 17742
17742 64232
64232 17523
17523 33388
33388 73908
73908 15412
15412 67920
679...

output:

250356248183316

result:

wrong answer 1st numbers differ - expected: '250413064505673', found: '250356248183316'

Test #14:

score: 0
Wrong Answer
time: 38ms
memory: 10964kb

input:

100000 5700
95638 43692
43692 52040
52040 29909
29909 66571
66571 20077
20077 28853
28853 20470
2047...

output:

250287415502922

result:

wrong answer 1st numbers differ - expected: '250814390051272', found: '250287415502922'

Test #15:

score: 0
Wrong Answer
time: 35ms
memory: 11756kb

input:

100000 73165
7735 42311
42311 26035
26035 44914
44914 71359
71359 9414
9414 21996
21996 19789
19789 ...

output:

249922648635989

result:

wrong answer 1st numbers differ - expected: '249949750624627', found: '249922648635989'

Test #16:

score: 0
Wrong Answer
time: 30ms
memory: 9652kb

input:

100000 81023
86193 9869
9869 79475
79475 88553
88553 54043
54043 91736
91736 23883
23883 68360
68360...

output:

249878480324149

result:

wrong answer 1st numbers differ - expected: '250402679195507', found: '249878480324149'

Test #17:

score: 0
Wrong Answer
time: 38ms
memory: 7172kb

input:

100000 53752
20439 68430
24723 68430
12283 20439
7861 12283
73785 68430
44056 24723
22482 7861
44454...

output:

251279364508346

result:

wrong answer 1st numbers differ - expected: '296233806565812', found: '251279364508346'

Test #18:

score: 0
Wrong Answer
time: 41ms
memory: 7204kb

input:

100000 81174
36555 78900
68651 36555
12967 78900
43832 36555
12851 36555
63272 43832
23048 12967
355...

output:

250482384157477

result:

wrong answer 1st numbers differ - expected: '296033950451487', found: '250482384157477'

Test #19:

score: 0
Wrong Answer
time: 37ms
memory: 7180kb

input:

100000 2143
44484 44643
28626 44484
80384 44643
33549 44484
89306 44643
57164 44484
73721 44643
4818...

output:

251053153724771

result:

wrong answer 1st numbers differ - expected: '296156367383787', found: '251053153724771'

Test #20:

score: 0
Wrong Answer
time: 40ms
memory: 7180kb

input:

100000 82182
62671 86050
89147 86050
37496 86050
31816 89147
83680 62671
19020 83680
42399 86050
751...

output:

250961477480821

result:

wrong answer 1st numbers differ - expected: '296278552690388', found: '250961477480821'