UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213266#3849. 旅行日记x_add_b5485ms4460kbC++11732b2024-11-10 10:28:362024-11-10 13:05:06

answer

#include<bits/stdc++.h>

#define N 100005
#define LL long long

using namespace std;

int n,s,u,v,pos;
int head[N];
bool vis[N];
LL ans;

struct Edge
{
	int u,v,nxt;
}e[N<<1];

void addEdge(int u,int v)
{
	e[++pos]={u,v,head[u]};
	head[u]=pos;
}

void solve(int st)
{
	priority_queue<int,vector<int>,greater<int>> q1;
	q1.push(st);
	vis[st]=true;
	int tmp=0;
	while(q1.size()){
		++tmp;
		int u=q1.top();
		q1.pop();
		ans+=tmp*u;
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(!vis[v]) vis[v]=true,q1.push(v);
		}
	}
}

int main()
{
	scanf("%d%d",&n,&s);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	solve(s);
	printf("%lld",ans);
}

详细

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

Test #1:

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

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: 1256kb

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: 0ms
memory: 1252kb

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: 1252kb

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: 1256kb

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: 1252kb

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: 0ms
memory: 1256kb

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: 1256kb

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: 0
Wrong Answer
time: 34ms
memory: 4452kb

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:

18104778547764

result:

wrong answer 1st numbers differ - expected: '333338198204980', found: '18104778547764'

Test #10:

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

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:

18108585638300

result:

wrong answer 1st numbers differ - expected: '333333415360924', found: '18108585638300'

Test #11:

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

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:

18107432550280

result:

wrong answer 1st numbers differ - expected: '333336557240200', found: '18107432550280'

Test #12:

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

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:

18104443843599

result:

wrong answer 1st numbers differ - expected: '333337863500815', found: '18104443843599'

Test #13:

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

input:

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

output:

23470305804820

result:

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

Test #14:

score: 0
Wrong Answer
time: 36ms
memory: 4072kb

input:

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

output:

23813789984842

result:

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

Test #15:

score: 0
Wrong Answer
time: 43ms
memory: 4068kb

input:

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

output:

23509152660053

result:

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

Test #16:

score: 0
Wrong Answer
time: 34ms
memory: 4072kb

input:

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

output:

23172926572085

result:

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

Test #17:

score: 0
Wrong Answer
time: 46ms
memory: 4084kb

input:

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

output:

23487184030394

result:

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

Test #18:

score: 0
Wrong Answer
time: 46ms
memory: 4080kb

input:

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

output:

24107542887205

result:

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

Test #19:

score: 0
Wrong Answer
time: 46ms
memory: 4080kb

input:

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

output:

23574505859427

result:

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

Test #20:

score: 0
Wrong Answer
time: 46ms
memory: 4080kb

input:

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

output:

23160707068277

result:

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