UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211848#3807. 随机游走x_add_b0739ms48060kbC++11965b2024-10-07 16:07:502024-10-29 10:32:31

answer

#include<bits/stdc++.h>

namespace IO
{
	template<typename Type>
	void read(Type &x){
		char ch=getchar();
		x=0;bool f=0;
		while(ch<'0'||ch>'9')
			f|=(ch=='-'),ch=getchar();
		while(ch>='0'&&ch<='9')
			x=((x<<1)+(x<<3)+(ch^48)),ch=getchar();
		x=f?-x:x;
	}
}

using namespace std;

#define N 500005
#define LL long long

int n,w;
int val[N],fa[N];
LL nowtime,ans;

bool opt1=true,opt2=true;

struct node
{
	int v,w;
	bool operator < (const node &a) const
	{
		return 1ll*w*val[a.v]<1ll*a.w*val[v];
	}
};

vector<node> Graph[N];

void dfs(int u)
{
	ans+=(nowtime*val[u]);
	for(int i=0;i<Graph[u].size();i++)
		dfs(Graph[u][i].v);
}

int main()
{
	IO::read(n);
	for(int i=2;i<=n;i++){
		IO::read(fa[i]);IO::read(w);
		Graph[fa[i]].push_back({i,w});
	}	
	for(int i=1;i<=n;i++)
		IO::read(val[i]);
	for(int i=1;i<=n;i++)
		sort(Graph[i].begin(),Graph[i].end());		
	dfs(1);
	printf("%lld",ans);
	return 0;
}

详细

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

Test #1:

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

input:

11
1 653
2 978
3 277
4 562
3 119
6 957
3 362
6 637
6 157
9 939
460 270 127 466 193 710 45 318 281 74...

output:

0

result:

wrong answer 1st lines differ - expected: '11506132', found: '0'

Test #2:

score: 0
Wrong Answer
time: 18ms
memory: 14848kb

input:

50000
1 983
1 937
2 776
4 753
2 494
2 683
2 335
4 316
7 274
6 638
11 535
10 872
13 808
13 817
11 94
...

output:

0

result:

wrong answer 1st lines differ - expected: '276117269146880', found: '0'

Test #3:

score: 0
Wrong Answer
time: 4ms
memory: 12948kb

input:

1000
1 729
1 239
1 433
1 445
1 877
1 648
1 284
1 814
1 287
1 941
1 183
1 126
1 65
1 500
1 823
1 725
...

output:

0

result:

wrong answer 1st lines differ - expected: '94592611925', found: '0'

Test #4:

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

input:

1000
1 790
1 229
1 462
1 658
1 880
1 507
1 109
1 66
1 356
1 477
1 963
1 689
1 284
1 962
1 896
1 671
...

output:

0

result:

wrong answer 1st lines differ - expected: '91654782236', found: '0'

Test #5:

score: 0
Wrong Answer
time: 95ms
memory: 48060kb

input:

500000
1 87
2 160
3 87
4 518
5 214
6 654
7 329
8 614
9 590
10 13
11 546
12 35
13 417
14 304
15 884
1...

output:

0

result:

wrong answer 1st lines differ - expected: '31331837945244749', found: '0'

Test #6:

score: 0
Wrong Answer
time: 113ms
memory: 20824kb

input:

500000
1 697
1 11
1 698
1 189
1 824
1 524
1 163
1 335
1 959
1 690
1 368
1 168
1 673
1 398
1 918
1 42...

output:

0

result:

wrong answer 1st lines differ - expected: '16263658814895739', found: '0'

Test #7:

score: 0
Wrong Answer
time: 120ms
memory: 20824kb

input:

500000
1 148
1 159
1 990
1 585
1 837
1 364
1 754
1 576
1 756
1 426
1 502
1 201
1 185
1 251
1 17
1 20...

output:

0

result:

wrong answer 1st lines differ - expected: '16307730758229655', found: '0'

Test #8:

score: 0
Wrong Answer
time: 123ms
memory: 24164kb

input:

500000
1 252
1 377
1 130
4 779
5 531
4 815
2 176
4 514
9 21
9 142
2 72
11 293
11 579
9 870
7 731
9 3...

output:

0

result:

wrong answer 1st lines differ - expected: '48685536049668', found: '0'

Test #9:

score: 0
Wrong Answer
time: 120ms
memory: 24184kb

input:

500000
1 484
1 48
3 523
2 793
4 822
1 622
3 874
4 54
6 568
4 867
11 500
7 974
4 966
7 793
1 140
1 40...

output:

0

result:

wrong answer 1st lines differ - expected: '49118321005585', found: '0'

Test #10:

score: 0
Wrong Answer
time: 146ms
memory: 24184kb

input:

500000
1 456
2 231
2 525
4 823
2 377
1 72
2 644
5 391
1 984
1 996
7 590
4 604
7 359
3 138
4 843
3 22...

output:

0

result:

wrong answer 1st lines differ - expected: '21539113052010528', found: '0'