/*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`....o+:-++/:--.```..-://s. `-` .- -` `-o: .-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -` :+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+` `-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -` `+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-` `:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-` `oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-` .-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-. ````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `- `.:--h.``..```
-.-`.- .- `+:--..`````..--//` `- /s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.- `//:--------://`
-` .-`.-` -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `- ``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `- `:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o. `.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `... ``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
// #pragma GCC optimize("branch-target-load-optimize")
// #pragma GCC optimize("branch-target-load-optimize2")
// #pragma GCC optimize("btr-bb-exclusive")
// #pragma comment(linker, "/STACK:367077216")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
//#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvll;
typedef vector<char> vc;
const int inf = 1e9 + 228;
const ll infll = 1e18;
const ll MOD = 1e9 + 7;
//static const int maxn = 1e6 + 228;
const ld eps = 1e-5;
const int K = 31;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = 3.1415926535;
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin);
// freopen("digit.out", "w", stdout);
}
const int maxn = 2e5 + 228;
vi g[maxn];
int dp[maxn];
string s;
int ans = 0;
void dfs(int v, int p = -1){
if(s[v] == '1'){
ans = max(ans, 1ll);
dp[v] = -1;
} else{
dp[v] = 0;
}
for(int i:g[v]){
if(i!=p){
dfs(i, v);
dp[v] += dp[i];
if(s[v]=='1'){
ans = max(dp[i]+1, ans);
}
}
}
if(s[v] == '1')
dp[v] = max(dp[v], 1ll);
ans = max(ans, dp[v]);
dp[v] = max(dp[v], 0ll);
}
void solve(){
int n;
cin >> n;
for(int i=0; i+1<n; i++){
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
cin >> s;
dfs(0);
// cout << dp[0] << endl;
// cout << dp[0] << endl;
cout << ans << endl;
}
signed main(){
fast_io();
srand(time(NULL));
// cout << fixed << setprecision(3);
int q = 1;
// cin >> q;
while(q--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
4 ms |
5120 KB |
Output is correct |
26 |
Correct |
4 ms |
5120 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5248 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
5 ms |
5248 KB |
Output is correct |
31 |
Correct |
4 ms |
5120 KB |
Output is correct |
32 |
Correct |
5 ms |
5120 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
4 ms |
5120 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
4 ms |
5120 KB |
Output is correct |
38 |
Correct |
4 ms |
5120 KB |
Output is correct |
39 |
Correct |
4 ms |
5120 KB |
Output is correct |
40 |
Correct |
4 ms |
5120 KB |
Output is correct |
41 |
Correct |
5 ms |
5248 KB |
Output is correct |
42 |
Correct |
5 ms |
5120 KB |
Output is correct |
43 |
Correct |
5 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
45 |
Correct |
5 ms |
5120 KB |
Output is correct |
46 |
Correct |
4 ms |
5120 KB |
Output is correct |
47 |
Correct |
5 ms |
5120 KB |
Output is correct |
48 |
Correct |
4 ms |
5236 KB |
Output is correct |
49 |
Correct |
5 ms |
5248 KB |
Output is correct |
50 |
Correct |
5 ms |
5120 KB |
Output is correct |
51 |
Correct |
4 ms |
5120 KB |
Output is correct |
52 |
Correct |
4 ms |
5120 KB |
Output is correct |
53 |
Correct |
5 ms |
5120 KB |
Output is correct |
54 |
Correct |
4 ms |
5120 KB |
Output is correct |
55 |
Correct |
4 ms |
5120 KB |
Output is correct |
56 |
Correct |
4 ms |
5120 KB |
Output is correct |
57 |
Correct |
4 ms |
5248 KB |
Output is correct |
58 |
Correct |
4 ms |
5120 KB |
Output is correct |
59 |
Correct |
4 ms |
5120 KB |
Output is correct |
60 |
Correct |
5 ms |
5120 KB |
Output is correct |
61 |
Correct |
4 ms |
5120 KB |
Output is correct |
62 |
Correct |
5 ms |
5248 KB |
Output is correct |
63 |
Correct |
4 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
4 ms |
5120 KB |
Output is correct |
26 |
Correct |
4 ms |
5120 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5248 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
5 ms |
5248 KB |
Output is correct |
31 |
Correct |
4 ms |
5120 KB |
Output is correct |
32 |
Correct |
5 ms |
5120 KB |
Output is correct |
33 |
Correct |
4 ms |
5120 KB |
Output is correct |
34 |
Correct |
4 ms |
5120 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
4 ms |
5120 KB |
Output is correct |
38 |
Correct |
4 ms |
5120 KB |
Output is correct |
39 |
Correct |
4 ms |
5120 KB |
Output is correct |
40 |
Correct |
4 ms |
5120 KB |
Output is correct |
41 |
Correct |
5 ms |
5248 KB |
Output is correct |
42 |
Correct |
5 ms |
5120 KB |
Output is correct |
43 |
Correct |
5 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
45 |
Correct |
5 ms |
5120 KB |
Output is correct |
46 |
Correct |
4 ms |
5120 KB |
Output is correct |
47 |
Correct |
5 ms |
5120 KB |
Output is correct |
48 |
Correct |
4 ms |
5236 KB |
Output is correct |
49 |
Correct |
5 ms |
5248 KB |
Output is correct |
50 |
Correct |
5 ms |
5120 KB |
Output is correct |
51 |
Correct |
4 ms |
5120 KB |
Output is correct |
52 |
Correct |
4 ms |
5120 KB |
Output is correct |
53 |
Correct |
5 ms |
5120 KB |
Output is correct |
54 |
Correct |
4 ms |
5120 KB |
Output is correct |
55 |
Correct |
4 ms |
5120 KB |
Output is correct |
56 |
Correct |
4 ms |
5120 KB |
Output is correct |
57 |
Correct |
4 ms |
5248 KB |
Output is correct |
58 |
Correct |
4 ms |
5120 KB |
Output is correct |
59 |
Correct |
4 ms |
5120 KB |
Output is correct |
60 |
Correct |
5 ms |
5120 KB |
Output is correct |
61 |
Correct |
4 ms |
5120 KB |
Output is correct |
62 |
Correct |
5 ms |
5248 KB |
Output is correct |
63 |
Correct |
4 ms |
5120 KB |
Output is correct |
64 |
Correct |
163 ms |
17048 KB |
Output is correct |
65 |
Correct |
166 ms |
17084 KB |
Output is correct |
66 |
Correct |
168 ms |
17256 KB |
Output is correct |
67 |
Correct |
163 ms |
17040 KB |
Output is correct |
68 |
Correct |
166 ms |
16936 KB |
Output is correct |
69 |
Correct |
167 ms |
17076 KB |
Output is correct |
70 |
Correct |
165 ms |
16968 KB |
Output is correct |
71 |
Correct |
166 ms |
16964 KB |
Output is correct |
72 |
Correct |
161 ms |
16948 KB |
Output is correct |
73 |
Correct |
188 ms |
23604 KB |
Output is correct |
74 |
Correct |
185 ms |
23480 KB |
Output is correct |
75 |
Correct |
169 ms |
18228 KB |
Output is correct |
76 |
Correct |
168 ms |
18236 KB |
Output is correct |
77 |
Correct |
171 ms |
16944 KB |
Output is correct |
78 |
Correct |
170 ms |
16952 KB |
Output is correct |
79 |
Correct |
167 ms |
17088 KB |
Output is correct |
80 |
Correct |
164 ms |
16948 KB |
Output is correct |
81 |
Correct |
132 ms |
17000 KB |
Output is correct |
82 |
Correct |
150 ms |
17008 KB |
Output is correct |
83 |
Correct |
183 ms |
20028 KB |
Output is correct |
84 |
Correct |
175 ms |
21316 KB |
Output is correct |
85 |
Correct |
173 ms |
21132 KB |
Output is correct |
86 |
Correct |
165 ms |
17848 KB |
Output is correct |
87 |
Correct |
157 ms |
17460 KB |
Output is correct |
88 |
Correct |
151 ms |
17652 KB |
Output is correct |
89 |
Correct |
148 ms |
17732 KB |
Output is correct |
90 |
Correct |
162 ms |
17560 KB |
Output is correct |
91 |
Correct |
159 ms |
17564 KB |
Output is correct |
92 |
Correct |
156 ms |
17832 KB |
Output is correct |
93 |
Correct |
149 ms |
18932 KB |
Output is correct |
94 |
Correct |
143 ms |
19984 KB |
Output is correct |
95 |
Correct |
141 ms |
19232 KB |
Output is correct |
96 |
Correct |
153 ms |
18104 KB |
Output is correct |
97 |
Correct |
158 ms |
17296 KB |
Output is correct |
98 |
Correct |
150 ms |
17128 KB |
Output is correct |
99 |
Correct |
160 ms |
17076 KB |
Output is correct |
100 |
Correct |
146 ms |
18724 KB |
Output is correct |
101 |
Correct |
145 ms |
17424 KB |
Output is correct |
102 |
Correct |
146 ms |
17160 KB |
Output is correct |
103 |
Correct |
157 ms |
17240 KB |
Output is correct |
104 |
Correct |
97 ms |
17692 KB |
Output is correct |
105 |
Correct |
188 ms |
21560 KB |
Output is correct |
106 |
Correct |
95 ms |
17648 KB |
Output is correct |
107 |
Correct |
97 ms |
17528 KB |
Output is correct |
108 |
Correct |
185 ms |
23992 KB |
Output is correct |
109 |
Correct |
93 ms |
17636 KB |
Output is correct |
110 |
Correct |
179 ms |
24248 KB |
Output is correct |
111 |
Correct |
150 ms |
16968 KB |
Output is correct |