Submission #763724

# Submission time Handle Problem Language Result Execution time Memory
763724 2023-06-22T17:22:45 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
115 ms 28500 KB
// Cu code roi se AC
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⡄⢠⡄⣠⠤⢤⡀⣤⠀⢠⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡏⠀⣿⠀⢨⡇⣿⠀⢸⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠈⠉⠉⠀⠈⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⢠⠤⣄⢠⡄⠀⣤⢀⣠⢤⡀⢠⡄⠀⡄⢠⡀⠀⢠⣤⣤⡀⠀⠀⠀⠀
// ⠀⠀⠀⠀⣙⠲⢦⢸⡗⠒⣿⢸⡁⠀⣿⢸⡇⠀⡇⢸⡇⠀⢸⡇⠀⡷⠀⠀⠀⠀
// ⠀⠀⠀⠀⠈⠛⠋⠈⠃⠀⠋⠀⠙⠛⠁⠀⠙⠛⠁⠘⠛⠛⠘⠛⠋⠁⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⢀⡀⢀⠀⡀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡷⣯⠀⢸⠀⡇⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠃⠈⠓⠘⠀⠛⠒⠂⠛⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⣀⠀⢀⡀⢀⣀⡀⠀⡀⠀⣀⢀⣀⣀⡀⢀⣀⣀⠀⣀⣀⡀⣀⠀⠀⢀⣀⣀⠀
// ⠀⠘⢷⠏⢰⡏⠀⢹⠄⡇⠀⣿⢸⣧⢤⡇⠘⠦⣬⡀⡧⠤⠄⣿⠀⠀⢸⠤⠄⠀
// ⠀⠀⠘⠀⠀⠛⠒⠋⠀⠛⠒⠋⠘⠃⠀⠓⠘⠲⠚⠁⠓⠒⠂⠛⠒⠒⠘⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⢀⠀⢀⣀⠀⢀⠀⢀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⢆⣸⢠⡏⠉⢹⡈⣇⡼⣇⣼⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠇⠈⠿⠀⠳⠶⠞⠀⠹⠇⠸⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠄⠄⠄⠄⠄⠄⠄⠄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⠄⠄⢀⣀⣀⣀⡀⠄⢀⣠⡔⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣰⢿⣿⣿⣿⣿⣿⣿⣷⡆⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⣻⣟⣿⣿⡿⣟⣛⣿⡃⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣧⣿⣾⣿⣷⣿⣷⣿⣿⣿⣷⣽⣹⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⡟⣟⣿⣿⠺⣟⣻⣿⣿⣿⡏⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⡝⠻⠵⠿⠿⢿⣿⣿⢳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣧⠈⣛⣛⣿⣿⡿⣡⣞⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡧⠄⠙⠛⠛⢁⣴⣿⣿⣷⣿⢿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⡿⠟⠉⠄⠄⢠⠄⣀⣠⣾⣿⣿⡿⠟⠁⠄⠈⠛⢿⣿⣿⣿⣿
// ⣿⣿⣿⣿⡟⠉⠄⠄⢀⠠⠐⠒⠐⠾⠿⢟⠋⠁⠄⢀⣀⠠⠐⠄⠂⠈⠻⢿⣿
// ⣿⣿⣿⠋⠁⠄⢀⡈⠄⠄⠄⠄⠄⠄⠄⠄⠁⠒⠉⠄⢠⣶⠄⠄⠄⠄⠄⠈⠫
// ⣿⣿⡟⠄⢔⠆⡀⠄⠈⢀⠄⠄⠄⠄⠄⠄⠄⢄⡀⠄⠈⡐⢠⠒⠄⠄⠄⠄⢀
// ⣿⣿⠁⡀⠄⠄⢇⠄⠄⢈⠆⠄⠄⢀⠔⠉⠁⠉⠉⠣⣖⠉⡂⡔⠂⠄⢀⠔⠁
// ⣿⡿⠄⠄⠄⠄⢰⠹⣗⣺⠤⠄⠰⡎⠄⠄⠄⠄⠄⠄⠘⢯⡶⢟⡠⠰⠄⠄

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using type=ll;
#define taskname "table"
// for Orac
#define tasknamein "table"
#define tasknameout "table"
#define fi first
#define se second
#define sz(v) ((type)(v).size())
#define all(v) (v).begin(), (v).end()
typedef pair<type, type> ii;      
typedef vector<ii> vii;      
typedef vector<type> vi;   
typedef vector<vector<type>> vvi;
//for FFT     
using cd = complex<double>;
const double PI = acos(-1);
const type MN=2e5+10;
const type oo=1e18;
const type llmax=0x3f3f3f3f3f3f;

type n, a, b, dp[MN], ans[MN];
vi AdjList[MN];
string s;

void dfs(type u, type v) {
	dp[u]-=(s[u]-'0');
	type Max=0;
	for(int i:AdjList[u]) {
		if(i!=v) {
			dfs(i, u);
			dp[u]+=dp[i];
			ans[u]=max(ans[u], dp[i]+(s[u]-'0'));
		}
	}
	dp[u]=max(dp[u], (type)(s[u]-'0'));
	ans[u]=max(ans[u], dp[u]);
}

void read() {
	cin >> n;
	for(int i=1; i<=n-1; i++) {
		cin >> a >> b;
		AdjList[a].push_back(b);
		AdjList[b].push_back(a);
	}
	cin >> s;
}

void sol(){
	s='#'+s;
	dfs(1, 1);
	cout << *max_element(ans + 1, ans + n + 1);
}

signed main() {
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    //for Orac
    /*
    ifstream in("tasknamein.txt");
    ofstream out("tasknameout.txt");
    */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    type t;
    // cin >> t;
    t=1;
    while(t--) {
    	read();  
    	sol();
    	cout << endl;
    }  
}

Compilation message

power.cpp: In function 'void dfs(type, type)':
power.cpp:64:7: warning: unused variable 'Max' [-Wunused-variable]
   64 |  type Max=0;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5104 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 4 ms 5104 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 2 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 3 ms 5140 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5104 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 4 ms 5104 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 2 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 3 ms 5140 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 87 ms 15772 KB Output is correct
65 Correct 89 ms 15816 KB Output is correct
66 Correct 94 ms 15844 KB Output is correct
67 Correct 77 ms 15812 KB Output is correct
68 Correct 85 ms 15800 KB Output is correct
69 Correct 89 ms 15812 KB Output is correct
70 Correct 115 ms 15812 KB Output is correct
71 Correct 114 ms 15948 KB Output is correct
72 Correct 87 ms 15824 KB Output is correct
73 Correct 95 ms 27452 KB Output is correct
74 Correct 92 ms 27332 KB Output is correct
75 Correct 82 ms 17008 KB Output is correct
76 Correct 80 ms 16996 KB Output is correct
77 Correct 87 ms 15800 KB Output is correct
78 Correct 84 ms 15684 KB Output is correct
79 Correct 76 ms 15788 KB Output is correct
80 Correct 88 ms 15752 KB Output is correct
81 Correct 64 ms 15792 KB Output is correct
82 Correct 75 ms 15612 KB Output is correct
83 Correct 98 ms 20908 KB Output is correct
84 Correct 86 ms 23008 KB Output is correct
85 Correct 89 ms 22716 KB Output is correct
86 Correct 78 ms 17160 KB Output is correct
87 Correct 80 ms 16452 KB Output is correct
88 Correct 73 ms 16656 KB Output is correct
89 Correct 73 ms 16636 KB Output is correct
90 Correct 74 ms 16504 KB Output is correct
91 Correct 73 ms 16724 KB Output is correct
92 Correct 73 ms 17060 KB Output is correct
93 Correct 93 ms 19292 KB Output is correct
94 Correct 79 ms 20992 KB Output is correct
95 Correct 72 ms 19444 KB Output is correct
96 Correct 72 ms 17752 KB Output is correct
97 Correct 71 ms 16380 KB Output is correct
98 Correct 70 ms 15992 KB Output is correct
99 Correct 72 ms 15812 KB Output is correct
100 Correct 80 ms 18736 KB Output is correct
101 Correct 73 ms 16632 KB Output is correct
102 Correct 77 ms 16016 KB Output is correct
103 Correct 72 ms 16128 KB Output is correct
104 Correct 55 ms 16296 KB Output is correct
105 Correct 89 ms 24140 KB Output is correct
106 Correct 58 ms 16408 KB Output is correct
107 Correct 46 ms 16400 KB Output is correct
108 Correct 90 ms 28112 KB Output is correct
109 Correct 55 ms 16376 KB Output is correct
110 Correct 90 ms 28500 KB Output is correct
111 Correct 73 ms 15656 KB Output is correct