Submission #296140

# Submission time Handle Problem Language Result Execution time Memory
296140 2020-09-10T10:21:11 Z Pyqe Power Plant (JOI20_power) C++14
100 / 100
426 ms 38152 KB
#include <bits/stdc++.h>

using namespace std;

long long n,dp[200069];
bitset<200069> a,vtd;
vector<long long> al[200069],dpl[200069];

void bd(long long x)
{
	long long i,sz=al[x].size(),l;
	
	vtd[x]=1;
	dp[x]=-a[x];
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		if(!vtd[l])
		{
			bd(l);
			dp[x]+=max(dp[l],(long long)a[l]);
		}
	}
}

void bd2(long long x,long long w)
{
	long long i,sz=al[x].size(),l;
	
	vtd[x]=1;
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		if(!vtd[l])
		{
			dpl[x][i]=max(dp[l],(long long)a[l]);
			bd2(l,max(w+dp[x]-dpl[x][i],(long long)a[x]));
		}
		else
		{
			dpl[x][i]=w;
		}
	}
}

int main()
{
	long long i,j,k,l,sz,sm,z,c=0;
	string s;
	
	scanf("%lld",&n);
	for(i=0;i<n-1;i++)
	{
		scanf("%lld%lld",&k,&l);
		al[k].push_back(l);
		al[l].push_back(k);
		dpl[k].push_back(0);
		dpl[l].push_back(0);
	}
	cin>>s;
	for(i=1;i<=n;i++)
	{
		a[i]=s[i-1]-'0';
		c+=a[i];
	}
	z=2*(c>=2);
	bd(1);
	vtd.reset();
	bd2(1,0);
	for(i=1;i<=n;i++)
	{
		sm=-a[i];
		sz=dpl[i].size();
		for(j=0;j<sz;j++)
		{
			sm+=dpl[i][j];
		}
		z=max(z,max(sm,(long long)a[i]));
	}
	printf("%lld\n",z);
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
power.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |   scanf("%lld%lld",&k,&l);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 8 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 7 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 8 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 7 ms 9728 KB Output is correct
22 Correct 8 ms 9984 KB Output is correct
23 Correct 8 ms 9964 KB Output is correct
24 Correct 8 ms 9984 KB Output is correct
25 Correct 9 ms 9984 KB Output is correct
26 Correct 8 ms 9984 KB Output is correct
27 Correct 9 ms 9984 KB Output is correct
28 Correct 8 ms 9984 KB Output is correct
29 Correct 10 ms 9984 KB Output is correct
30 Correct 10 ms 9984 KB Output is correct
31 Correct 8 ms 9984 KB Output is correct
32 Correct 9 ms 9984 KB Output is correct
33 Correct 9 ms 9984 KB Output is correct
34 Correct 8 ms 9984 KB Output is correct
35 Correct 8 ms 9984 KB Output is correct
36 Correct 8 ms 9984 KB Output is correct
37 Correct 8 ms 9984 KB Output is correct
38 Correct 8 ms 9984 KB Output is correct
39 Correct 9 ms 9984 KB Output is correct
40 Correct 8 ms 9984 KB Output is correct
41 Correct 8 ms 9984 KB Output is correct
42 Correct 8 ms 9984 KB Output is correct
43 Correct 9 ms 9984 KB Output is correct
44 Correct 8 ms 9984 KB Output is correct
45 Correct 8 ms 9984 KB Output is correct
46 Correct 8 ms 9984 KB Output is correct
47 Correct 8 ms 9984 KB Output is correct
48 Correct 9 ms 9984 KB Output is correct
49 Correct 9 ms 9984 KB Output is correct
50 Correct 8 ms 9984 KB Output is correct
51 Correct 8 ms 9984 KB Output is correct
52 Correct 9 ms 10016 KB Output is correct
53 Correct 8 ms 9984 KB Output is correct
54 Correct 8 ms 10008 KB Output is correct
55 Correct 9 ms 9984 KB Output is correct
56 Correct 8 ms 9984 KB Output is correct
57 Correct 8 ms 9984 KB Output is correct
58 Correct 8 ms 9984 KB Output is correct
59 Correct 8 ms 9984 KB Output is correct
60 Correct 8 ms 9984 KB Output is correct
61 Correct 8 ms 9984 KB Output is correct
62 Correct 8 ms 9984 KB Output is correct
63 Correct 8 ms 9984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 8 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 7 ms 9728 KB Output is correct
22 Correct 8 ms 9984 KB Output is correct
23 Correct 8 ms 9964 KB Output is correct
24 Correct 8 ms 9984 KB Output is correct
25 Correct 9 ms 9984 KB Output is correct
26 Correct 8 ms 9984 KB Output is correct
27 Correct 9 ms 9984 KB Output is correct
28 Correct 8 ms 9984 KB Output is correct
29 Correct 10 ms 9984 KB Output is correct
30 Correct 10 ms 9984 KB Output is correct
31 Correct 8 ms 9984 KB Output is correct
32 Correct 9 ms 9984 KB Output is correct
33 Correct 9 ms 9984 KB Output is correct
34 Correct 8 ms 9984 KB Output is correct
35 Correct 8 ms 9984 KB Output is correct
36 Correct 8 ms 9984 KB Output is correct
37 Correct 8 ms 9984 KB Output is correct
38 Correct 8 ms 9984 KB Output is correct
39 Correct 9 ms 9984 KB Output is correct
40 Correct 8 ms 9984 KB Output is correct
41 Correct 8 ms 9984 KB Output is correct
42 Correct 8 ms 9984 KB Output is correct
43 Correct 9 ms 9984 KB Output is correct
44 Correct 8 ms 9984 KB Output is correct
45 Correct 8 ms 9984 KB Output is correct
46 Correct 8 ms 9984 KB Output is correct
47 Correct 8 ms 9984 KB Output is correct
48 Correct 9 ms 9984 KB Output is correct
49 Correct 9 ms 9984 KB Output is correct
50 Correct 8 ms 9984 KB Output is correct
51 Correct 8 ms 9984 KB Output is correct
52 Correct 9 ms 10016 KB Output is correct
53 Correct 8 ms 9984 KB Output is correct
54 Correct 8 ms 10008 KB Output is correct
55 Correct 9 ms 9984 KB Output is correct
56 Correct 8 ms 9984 KB Output is correct
57 Correct 8 ms 9984 KB Output is correct
58 Correct 8 ms 9984 KB Output is correct
59 Correct 8 ms 9984 KB Output is correct
60 Correct 8 ms 9984 KB Output is correct
61 Correct 8 ms 9984 KB Output is correct
62 Correct 8 ms 9984 KB Output is correct
63 Correct 8 ms 9984 KB Output is correct
64 Correct 370 ms 26508 KB Output is correct
65 Correct 369 ms 26572 KB Output is correct
66 Correct 390 ms 26508 KB Output is correct
67 Correct 386 ms 26632 KB Output is correct
68 Correct 370 ms 26480 KB Output is correct
69 Correct 368 ms 26504 KB Output is correct
70 Correct 380 ms 26504 KB Output is correct
71 Correct 376 ms 26448 KB Output is correct
72 Correct 378 ms 26644 KB Output is correct
73 Correct 426 ms 37000 KB Output is correct
74 Correct 405 ms 37000 KB Output is correct
75 Correct 377 ms 28808 KB Output is correct
76 Correct 393 ms 29064 KB Output is correct
77 Correct 391 ms 26432 KB Output is correct
78 Correct 389 ms 26500 KB Output is correct
79 Correct 385 ms 26536 KB Output is correct
80 Correct 375 ms 26504 KB Output is correct
81 Correct 308 ms 26716 KB Output is correct
82 Correct 344 ms 26472 KB Output is correct
83 Correct 412 ms 31496 KB Output is correct
84 Correct 415 ms 33672 KB Output is correct
85 Correct 397 ms 33416 KB Output is correct
86 Correct 384 ms 27860 KB Output is correct
87 Correct 373 ms 27400 KB Output is correct
88 Correct 369 ms 27524 KB Output is correct
89 Correct 374 ms 27536 KB Output is correct
90 Correct 365 ms 27296 KB Output is correct
91 Correct 370 ms 27524 KB Output is correct
92 Correct 368 ms 27912 KB Output is correct
93 Correct 380 ms 29800 KB Output is correct
94 Correct 364 ms 31456 KB Output is correct
95 Correct 360 ms 30180 KB Output is correct
96 Correct 367 ms 28316 KB Output is correct
97 Correct 375 ms 27020 KB Output is correct
98 Correct 341 ms 26760 KB Output is correct
99 Correct 368 ms 26528 KB Output is correct
100 Correct 369 ms 29488 KB Output is correct
101 Correct 366 ms 27144 KB Output is correct
102 Correct 333 ms 26628 KB Output is correct
103 Correct 369 ms 26888 KB Output is correct
104 Correct 234 ms 27596 KB Output is correct
105 Correct 424 ms 33800 KB Output is correct
106 Correct 233 ms 27604 KB Output is correct
107 Correct 224 ms 27604 KB Output is correct
108 Correct 409 ms 37948 KB Output is correct
109 Correct 228 ms 27604 KB Output is correct
110 Correct 407 ms 38152 KB Output is correct
111 Correct 353 ms 26376 KB Output is correct