UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201711#3514. sigmaJosephcheng100577ms8216kbC++11666b2024-02-05 09:12:482024-02-05 12:20:19

answer

#include<bits/stdc++.h>
using namespace std;

int n,u,v,pos,ans;
int head[200005],val[200005],sum[200005];

struct Edge
{
	int u,v,nxt;
}e[400005];

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

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&val[i]);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	for(int u=1;u<=n;u++){
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			sum[u]+=val[v];
		}
	}
	for(int u=1;u<=n;u++){
		ans=0;
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			ans+=sum[v];
			ans-=val[u];
		}
		printf("%d ",ans);
	}
}

详细

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1272kb

input:

2000
1123 6113 5134 9887 2716 2941 6533 7414 1115 4946 5263 7527 8532 7889 1460 8629 5379 578 2641 6...

output:

230646 248743 235278 279905 181119 202928 191861 176421 185391 207990 226220 198342 278967 286628 19...

result:

ok single line: '230646 248743 235278 279905 18...62 198880 238406 192268 253155 '

Test #2:

score: 10
Accepted
time: 1ms
memory: 1268kb

input:

2000
2125 4707 1325 1212 5524 8344 6630 356 169 3939 9073 9174 4874 5307 2198 5092 2438 7114 3518 85...

output:

223188 260418 246551 315586 232773 222848 200025 250947 195473 237460 191671 215298 246429 236092 17...

result:

ok single line: '223188 260418 246551 315586 23...90 197983 274451 246420 220702 '

Test #3:

score: 10
Accepted
time: 1ms
memory: 1272kb

input:

2000
6838 2980 5477 6197 1187 139 4610 8571 1908 9679 3257 93 969 3830 7932 5393 7714 3079 1904 1440...

output:

298227 291153 179805 205308 235766 239190 305397 206177 275566 216207 275509 227956 179993 284454 23...

result:

ok single line: '298227 291153 179805 205308 23...61 246833 224367 203277 285934 '

Test #4:

score: 10
Accepted
time: 85ms
memory: 8216kb

input:

200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

450 453 442 441 446 465 458 430 482 461 452 446 459 438 461 485 427 458 462 468 441 457 464 499 455 ...

result:

ok single line: '450 453 442 441 446 465 458 43...33 442 432 477 474 442 455 433 '

Test #5:

score: 10
Accepted
time: 80ms
memory: 8212kb

input:

200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

413 462 445 428 493 412 462 415 422 446 452 452 468 435 466 477 462 441 450 435 461 432 461 436 480 ...

result:

ok single line: '413 462 445 428 493 412 462 41...37 453 448 480 438 444 489 411 '

Test #6:

score: 10
Accepted
time: 81ms
memory: 8212kb

input:

200000
8425 7223 1370 8463 7105 7576 9030 2148 3540 9710 4553 723 512 4162 5037 5776 633 879 7711 71...

output:

2443237 2138790 2409553 2326788 2198356 2457252 2210369 2281249 2040419 2164344 2166248 2295533 2393...

result:

ok single line: '2443237 2138790 2409553 232678...176035 2231829 2178999 2393573 '

Test #7:

score: 10
Accepted
time: 84ms
memory: 8216kb

input:

200000
591 822 4135 1614 3874 2657 3649 8902 4046 9679 7277 2761 3381 1701 8958 8539 9644 7789 1851 ...

output:

2257752 2182246 2398922 2187369 2304172 2139960 2178453 2287107 2263737 2282300 1995398 2336046 2251...

result:

ok single line: '2257752 2182246 2398922 218736...141932 2065886 2195128 2244543 '

Test #8:

score: 10
Accepted
time: 90ms
memory: 8216kb

input:

200000
2458 4232 9782 3433 9814 3355 3323 3508 3957 3907 7679 7868 9452 8181 127 1039 3185 7977 623 ...

output:

2072989 2139998 2251160 2220169 2419864 2353186 2233474 2291667 2222847 2335767 2359002 2213071 2307...

result:

ok single line: '2072989 2139998 2251160 222016...180623 2362548 2219719 2133778 '

Test #9:

score: 10
Accepted
time: 90ms
memory: 8212kb

input:

200000
6985 5363 9585 4898 1714 7190 2465 165 9446 6343 4177 7917 6024 8180 995 953 3052 223 4065 49...

output:

2342284 2501487 2153670 2319678 2322862 2430600 2287156 2319881 2232315 2266092 2502673 2498933 2351...

result:

ok single line: '2342284 2501487 2153670 231967...046023 2218100 2478989 2246003 '

Test #10:

score: 10
Accepted
time: 65ms
memory: 8216kb

input:

200000
9458 6559 3561 6259 939 9082 2789 6907 6489 8156 4708 9880 5118 6703 1633 4382 9278 6016 1340...

output:

2020506 2489226 2225138 2331025 2167081 2037852 2108325 2319372 2344745 2013345 2303104 2143744 2316...

result:

ok single line: '2020506 2489226 2225138 233102...090003 2254734 2391663 2411905 '