# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
818419 | 2023-08-10T04:46:43 Z | vjudge1 | Power Plant (JOI20_power) | C++17 | 199 ms | 37000 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 5e5 + 9 , mod = 1e9 + 7; ll d[N] , a[N] = {}, dp[N] , b[N] , c[N]; vector<int>v[N]; void dfs(int n , int p = 0){ for(auto to : v[n]) if(to != p) dfs(to , n); for(auto to : v[n]) if(to != p) if(dp[to] + b[n] >= c[n]) c[n] = dp[to] + b[n]; dp[n] -= b[n]; dp[n] = max(dp[n] , b[n]); dp[p] += dp[n]; } void solve(){ ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n; for(i = 1; i < n; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); } string a; cin>>a; for(i = 1; i <= n; i++) b[i] = (a[i - 1] == '1'); dfs(1); for(i = 1; i <= n; i++) mx = max({mx , c[i] , dp[i]}); cout<<mx<<"\n"; } int main(){ /* TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12052 KB | Output is correct |
2 | Correct | 7 ms | 12056 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 7 ms | 12048 KB | Output is correct |
6 | Correct | 7 ms | 12048 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 7 ms | 11988 KB | Output is correct |
10 | Correct | 5 ms | 11988 KB | Output is correct |
11 | Correct | 7 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 12052 KB | Output is correct |
14 | Correct | 6 ms | 12048 KB | Output is correct |
15 | Correct | 6 ms | 11964 KB | Output is correct |
16 | Correct | 5 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 12036 KB | Output is correct |
19 | Correct | 6 ms | 12056 KB | Output is correct |
20 | Correct | 6 ms | 11988 KB | Output is correct |
21 | Correct | 7 ms | 11988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12052 KB | Output is correct |
2 | Correct | 7 ms | 12056 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 7 ms | 12048 KB | Output is correct |
6 | Correct | 7 ms | 12048 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 7 ms | 11988 KB | Output is correct |
10 | Correct | 5 ms | 11988 KB | Output is correct |
11 | Correct | 7 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 12052 KB | Output is correct |
14 | Correct | 6 ms | 12048 KB | Output is correct |
15 | Correct | 6 ms | 11964 KB | Output is correct |
16 | Correct | 5 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 12036 KB | Output is correct |
19 | Correct | 6 ms | 12056 KB | Output is correct |
20 | Correct | 6 ms | 11988 KB | Output is correct |
21 | Correct | 7 ms | 11988 KB | Output is correct |
22 | Correct | 6 ms | 12116 KB | Output is correct |
23 | Correct | 7 ms | 12116 KB | Output is correct |
24 | Correct | 6 ms | 12112 KB | Output is correct |
25 | Correct | 7 ms | 12116 KB | Output is correct |
26 | Correct | 7 ms | 12116 KB | Output is correct |
27 | Correct | 7 ms | 12136 KB | Output is correct |
28 | Correct | 7 ms | 12116 KB | Output is correct |
29 | Correct | 7 ms | 12244 KB | Output is correct |
30 | Correct | 7 ms | 12244 KB | Output is correct |
31 | Correct | 6 ms | 12096 KB | Output is correct |
32 | Correct | 7 ms | 12116 KB | Output is correct |
33 | Correct | 7 ms | 12148 KB | Output is correct |
34 | Correct | 6 ms | 12116 KB | Output is correct |
35 | Correct | 7 ms | 12148 KB | Output is correct |
36 | Correct | 7 ms | 12188 KB | Output is correct |
37 | Correct | 7 ms | 12192 KB | Output is correct |
38 | Correct | 7 ms | 12244 KB | Output is correct |
39 | Correct | 8 ms | 12244 KB | Output is correct |
40 | Correct | 7 ms | 12116 KB | Output is correct |
41 | Correct | 7 ms | 12188 KB | Output is correct |
42 | Correct | 8 ms | 12116 KB | Output is correct |
43 | Correct | 8 ms | 12140 KB | Output is correct |
44 | Correct | 8 ms | 12116 KB | Output is correct |
45 | Correct | 7 ms | 12192 KB | Output is correct |
46 | Correct | 6 ms | 12188 KB | Output is correct |
47 | Correct | 7 ms | 12116 KB | Output is correct |
48 | Correct | 7 ms | 12244 KB | Output is correct |
49 | Correct | 7 ms | 12244 KB | Output is correct |
50 | Correct | 7 ms | 12116 KB | Output is correct |
51 | Correct | 6 ms | 12116 KB | Output is correct |
52 | Correct | 7 ms | 12188 KB | Output is correct |
53 | Correct | 7 ms | 12192 KB | Output is correct |
54 | Correct | 7 ms | 12128 KB | Output is correct |
55 | Correct | 7 ms | 12116 KB | Output is correct |
56 | Correct | 6 ms | 12192 KB | Output is correct |
57 | Correct | 7 ms | 12244 KB | Output is correct |
58 | Correct | 7 ms | 12192 KB | Output is correct |
59 | Correct | 8 ms | 12196 KB | Output is correct |
60 | Correct | 7 ms | 12216 KB | Output is correct |
61 | Correct | 6 ms | 12116 KB | Output is correct |
62 | Correct | 7 ms | 12244 KB | Output is correct |
63 | Correct | 7 ms | 12116 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12052 KB | Output is correct |
2 | Correct | 7 ms | 12056 KB | Output is correct |
3 | Correct | 6 ms | 11988 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 7 ms | 12048 KB | Output is correct |
6 | Correct | 7 ms | 12048 KB | Output is correct |
7 | Correct | 6 ms | 11988 KB | Output is correct |
8 | Correct | 6 ms | 11988 KB | Output is correct |
9 | Correct | 7 ms | 11988 KB | Output is correct |
10 | Correct | 5 ms | 11988 KB | Output is correct |
11 | Correct | 7 ms | 11988 KB | Output is correct |
12 | Correct | 6 ms | 11988 KB | Output is correct |
13 | Correct | 6 ms | 12052 KB | Output is correct |
14 | Correct | 6 ms | 12048 KB | Output is correct |
15 | Correct | 6 ms | 11964 KB | Output is correct |
16 | Correct | 5 ms | 11988 KB | Output is correct |
17 | Correct | 6 ms | 11988 KB | Output is correct |
18 | Correct | 6 ms | 12036 KB | Output is correct |
19 | Correct | 6 ms | 12056 KB | Output is correct |
20 | Correct | 6 ms | 11988 KB | Output is correct |
21 | Correct | 7 ms | 11988 KB | Output is correct |
22 | Correct | 6 ms | 12116 KB | Output is correct |
23 | Correct | 7 ms | 12116 KB | Output is correct |
24 | Correct | 6 ms | 12112 KB | Output is correct |
25 | Correct | 7 ms | 12116 KB | Output is correct |
26 | Correct | 7 ms | 12116 KB | Output is correct |
27 | Correct | 7 ms | 12136 KB | Output is correct |
28 | Correct | 7 ms | 12116 KB | Output is correct |
29 | Correct | 7 ms | 12244 KB | Output is correct |
30 | Correct | 7 ms | 12244 KB | Output is correct |
31 | Correct | 6 ms | 12096 KB | Output is correct |
32 | Correct | 7 ms | 12116 KB | Output is correct |
33 | Correct | 7 ms | 12148 KB | Output is correct |
34 | Correct | 6 ms | 12116 KB | Output is correct |
35 | Correct | 7 ms | 12148 KB | Output is correct |
36 | Correct | 7 ms | 12188 KB | Output is correct |
37 | Correct | 7 ms | 12192 KB | Output is correct |
38 | Correct | 7 ms | 12244 KB | Output is correct |
39 | Correct | 8 ms | 12244 KB | Output is correct |
40 | Correct | 7 ms | 12116 KB | Output is correct |
41 | Correct | 7 ms | 12188 KB | Output is correct |
42 | Correct | 8 ms | 12116 KB | Output is correct |
43 | Correct | 8 ms | 12140 KB | Output is correct |
44 | Correct | 8 ms | 12116 KB | Output is correct |
45 | Correct | 7 ms | 12192 KB | Output is correct |
46 | Correct | 6 ms | 12188 KB | Output is correct |
47 | Correct | 7 ms | 12116 KB | Output is correct |
48 | Correct | 7 ms | 12244 KB | Output is correct |
49 | Correct | 7 ms | 12244 KB | Output is correct |
50 | Correct | 7 ms | 12116 KB | Output is correct |
51 | Correct | 6 ms | 12116 KB | Output is correct |
52 | Correct | 7 ms | 12188 KB | Output is correct |
53 | Correct | 7 ms | 12192 KB | Output is correct |
54 | Correct | 7 ms | 12128 KB | Output is correct |
55 | Correct | 7 ms | 12116 KB | Output is correct |
56 | Correct | 6 ms | 12192 KB | Output is correct |
57 | Correct | 7 ms | 12244 KB | Output is correct |
58 | Correct | 7 ms | 12192 KB | Output is correct |
59 | Correct | 8 ms | 12196 KB | Output is correct |
60 | Correct | 7 ms | 12216 KB | Output is correct |
61 | Correct | 6 ms | 12116 KB | Output is correct |
62 | Correct | 7 ms | 12244 KB | Output is correct |
63 | Correct | 7 ms | 12116 KB | Output is correct |
64 | Correct | 148 ms | 26112 KB | Output is correct |
65 | Correct | 155 ms | 26044 KB | Output is correct |
66 | Correct | 152 ms | 26152 KB | Output is correct |
67 | Correct | 142 ms | 26152 KB | Output is correct |
68 | Correct | 163 ms | 26036 KB | Output is correct |
69 | Correct | 156 ms | 26240 KB | Output is correct |
70 | Correct | 153 ms | 26120 KB | Output is correct |
71 | Correct | 157 ms | 26044 KB | Output is correct |
72 | Correct | 165 ms | 26172 KB | Output is correct |
73 | Correct | 151 ms | 36212 KB | Output is correct |
74 | Correct | 165 ms | 36172 KB | Output is correct |
75 | Correct | 142 ms | 26048 KB | Output is correct |
76 | Correct | 147 ms | 26056 KB | Output is correct |
77 | Correct | 175 ms | 26040 KB | Output is correct |
78 | Correct | 159 ms | 26036 KB | Output is correct |
79 | Correct | 156 ms | 26044 KB | Output is correct |
80 | Correct | 146 ms | 26036 KB | Output is correct |
81 | Correct | 125 ms | 26444 KB | Output is correct |
82 | Correct | 148 ms | 26280 KB | Output is correct |
83 | Correct | 156 ms | 30212 KB | Output is correct |
84 | Correct | 170 ms | 31940 KB | Output is correct |
85 | Correct | 199 ms | 31660 KB | Output is correct |
86 | Correct | 162 ms | 27152 KB | Output is correct |
87 | Correct | 188 ms | 26732 KB | Output is correct |
88 | Correct | 158 ms | 27232 KB | Output is correct |
89 | Correct | 140 ms | 27232 KB | Output is correct |
90 | Correct | 163 ms | 27060 KB | Output is correct |
91 | Correct | 164 ms | 27176 KB | Output is correct |
92 | Correct | 138 ms | 27540 KB | Output is correct |
93 | Correct | 182 ms | 29268 KB | Output is correct |
94 | Correct | 136 ms | 30700 KB | Output is correct |
95 | Correct | 147 ms | 29600 KB | Output is correct |
96 | Correct | 138 ms | 28292 KB | Output is correct |
97 | Correct | 166 ms | 27040 KB | Output is correct |
98 | Correct | 161 ms | 26700 KB | Output is correct |
99 | Correct | 140 ms | 26444 KB | Output is correct |
100 | Correct | 138 ms | 29072 KB | Output is correct |
101 | Correct | 162 ms | 27492 KB | Output is correct |
102 | Correct | 134 ms | 26752 KB | Output is correct |
103 | Correct | 143 ms | 26636 KB | Output is correct |
104 | Correct | 121 ms | 25456 KB | Output is correct |
105 | Correct | 188 ms | 33616 KB | Output is correct |
106 | Correct | 116 ms | 25284 KB | Output is correct |
107 | Correct | 113 ms | 25308 KB | Output is correct |
108 | Correct | 150 ms | 36832 KB | Output is correct |
109 | Correct | 118 ms | 25436 KB | Output is correct |
110 | Correct | 186 ms | 37000 KB | Output is correct |
111 | Correct | 155 ms | 26028 KB | Output is correct |