답안 #503780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503780 2022-01-08T21:49:03 Z Abrar_Al_Samit Power Plant (JOI20_power) C++17
100 / 100
163 ms 31592 KB
#include<bits/stdc++.h>
using namespace std;
const int MX = 200005;
vector<int>g[MX];
int n;
int dp[MX];
string s;
int ans;
int solve(int v, int p=-1) {
  int &ret = dp[v];
  if(ret!=-1) return ret;
  ret = 0;
  if(s[v]=='0') {
    for(auto u : g[v]) if(u!=p) {
      ret += solve(u, v);
    }
  } else {
    int mx = 0, sum = 0;
    for(auto u : g[v]) if(u!=p) {
      mx = max(mx, solve(u, v));
      sum += solve(u, v);
    }
    mx += 1;
    sum -= 1;
    ans = max({mx, ans, sum});
    ret = max(1, sum);
  }
  return ret;
}
void PlayGround() {
  cin >> n;
  for(int i=1; i<n; ++i) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cin >> s;
  s = "#" + s;
  memset(dp, -1, sizeof dp);
  cout << max(ans, solve(1)) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5720 KB Output is correct
7 Correct 2 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
9 Correct 3 ms 5708 KB Output is correct
10 Correct 4 ms 5708 KB Output is correct
11 Correct 3 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 3 ms 5708 KB Output is correct
16 Correct 3 ms 5708 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 3 ms 5764 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 2 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5720 KB Output is correct
7 Correct 2 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
9 Correct 3 ms 5708 KB Output is correct
10 Correct 4 ms 5708 KB Output is correct
11 Correct 3 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 3 ms 5708 KB Output is correct
16 Correct 3 ms 5708 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 3 ms 5764 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 2 ms 5708 KB Output is correct
22 Correct 3 ms 5836 KB Output is correct
23 Correct 3 ms 5800 KB Output is correct
24 Correct 4 ms 5836 KB Output is correct
25 Correct 4 ms 5792 KB Output is correct
26 Correct 3 ms 5788 KB Output is correct
27 Correct 4 ms 5836 KB Output is correct
28 Correct 5 ms 5796 KB Output is correct
29 Correct 5 ms 5920 KB Output is correct
30 Correct 4 ms 5964 KB Output is correct
31 Correct 3 ms 5836 KB Output is correct
32 Correct 4 ms 5836 KB Output is correct
33 Correct 3 ms 5836 KB Output is correct
34 Correct 5 ms 5836 KB Output is correct
35 Correct 3 ms 5836 KB Output is correct
36 Correct 4 ms 5800 KB Output is correct
37 Correct 3 ms 5836 KB Output is correct
38 Correct 4 ms 5836 KB Output is correct
39 Correct 4 ms 5964 KB Output is correct
40 Correct 4 ms 5860 KB Output is correct
41 Correct 3 ms 5836 KB Output is correct
42 Correct 3 ms 5836 KB Output is correct
43 Correct 4 ms 5836 KB Output is correct
44 Correct 4 ms 5836 KB Output is correct
45 Correct 3 ms 5836 KB Output is correct
46 Correct 4 ms 5836 KB Output is correct
47 Correct 4 ms 5836 KB Output is correct
48 Correct 5 ms 5968 KB Output is correct
49 Correct 3 ms 5964 KB Output is correct
50 Correct 3 ms 5836 KB Output is correct
51 Correct 3 ms 5836 KB Output is correct
52 Correct 4 ms 5836 KB Output is correct
53 Correct 3 ms 5792 KB Output is correct
54 Correct 3 ms 5836 KB Output is correct
55 Correct 4 ms 5836 KB Output is correct
56 Correct 4 ms 5784 KB Output is correct
57 Correct 4 ms 5964 KB Output is correct
58 Correct 3 ms 5836 KB Output is correct
59 Correct 4 ms 5876 KB Output is correct
60 Correct 3 ms 5928 KB Output is correct
61 Correct 3 ms 5796 KB Output is correct
62 Correct 4 ms 5964 KB Output is correct
63 Correct 4 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5720 KB Output is correct
7 Correct 2 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
9 Correct 3 ms 5708 KB Output is correct
10 Correct 4 ms 5708 KB Output is correct
11 Correct 3 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 3 ms 5708 KB Output is correct
16 Correct 3 ms 5708 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 3 ms 5764 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 2 ms 5708 KB Output is correct
22 Correct 3 ms 5836 KB Output is correct
23 Correct 3 ms 5800 KB Output is correct
24 Correct 4 ms 5836 KB Output is correct
25 Correct 4 ms 5792 KB Output is correct
26 Correct 3 ms 5788 KB Output is correct
27 Correct 4 ms 5836 KB Output is correct
28 Correct 5 ms 5796 KB Output is correct
29 Correct 5 ms 5920 KB Output is correct
30 Correct 4 ms 5964 KB Output is correct
31 Correct 3 ms 5836 KB Output is correct
32 Correct 4 ms 5836 KB Output is correct
33 Correct 3 ms 5836 KB Output is correct
34 Correct 5 ms 5836 KB Output is correct
35 Correct 3 ms 5836 KB Output is correct
36 Correct 4 ms 5800 KB Output is correct
37 Correct 3 ms 5836 KB Output is correct
38 Correct 4 ms 5836 KB Output is correct
39 Correct 4 ms 5964 KB Output is correct
40 Correct 4 ms 5860 KB Output is correct
41 Correct 3 ms 5836 KB Output is correct
42 Correct 3 ms 5836 KB Output is correct
43 Correct 4 ms 5836 KB Output is correct
44 Correct 4 ms 5836 KB Output is correct
45 Correct 3 ms 5836 KB Output is correct
46 Correct 4 ms 5836 KB Output is correct
47 Correct 4 ms 5836 KB Output is correct
48 Correct 5 ms 5968 KB Output is correct
49 Correct 3 ms 5964 KB Output is correct
50 Correct 3 ms 5836 KB Output is correct
51 Correct 3 ms 5836 KB Output is correct
52 Correct 4 ms 5836 KB Output is correct
53 Correct 3 ms 5792 KB Output is correct
54 Correct 3 ms 5836 KB Output is correct
55 Correct 4 ms 5836 KB Output is correct
56 Correct 4 ms 5784 KB Output is correct
57 Correct 4 ms 5964 KB Output is correct
58 Correct 3 ms 5836 KB Output is correct
59 Correct 4 ms 5876 KB Output is correct
60 Correct 3 ms 5928 KB Output is correct
61 Correct 3 ms 5796 KB Output is correct
62 Correct 4 ms 5964 KB Output is correct
63 Correct 4 ms 5836 KB Output is correct
64 Correct 135 ms 15092 KB Output is correct
65 Correct 103 ms 15144 KB Output is correct
66 Correct 121 ms 15148 KB Output is correct
67 Correct 153 ms 15164 KB Output is correct
68 Correct 107 ms 15200 KB Output is correct
69 Correct 127 ms 15304 KB Output is correct
70 Correct 132 ms 15200 KB Output is correct
71 Correct 105 ms 15176 KB Output is correct
72 Correct 138 ms 15164 KB Output is correct
73 Correct 163 ms 30260 KB Output is correct
74 Correct 127 ms 30228 KB Output is correct
75 Correct 136 ms 15144 KB Output is correct
76 Correct 101 ms 15008 KB Output is correct
77 Correct 114 ms 15084 KB Output is correct
78 Correct 124 ms 15068 KB Output is correct
79 Correct 112 ms 15092 KB Output is correct
80 Correct 104 ms 15084 KB Output is correct
81 Correct 88 ms 15408 KB Output is correct
82 Correct 109 ms 15216 KB Output is correct
83 Correct 116 ms 21336 KB Output is correct
84 Correct 142 ms 23884 KB Output is correct
85 Correct 133 ms 23396 KB Output is correct
86 Correct 129 ms 16808 KB Output is correct
87 Correct 142 ms 16032 KB Output is correct
88 Correct 111 ms 16456 KB Output is correct
89 Correct 108 ms 16596 KB Output is correct
90 Correct 97 ms 16252 KB Output is correct
91 Correct 115 ms 16484 KB Output is correct
92 Correct 102 ms 16900 KB Output is correct
93 Correct 127 ms 19984 KB Output is correct
94 Correct 103 ms 21988 KB Output is correct
95 Correct 101 ms 20260 KB Output is correct
96 Correct 111 ms 18228 KB Output is correct
97 Correct 111 ms 16348 KB Output is correct
98 Correct 109 ms 15660 KB Output is correct
99 Correct 103 ms 15668 KB Output is correct
100 Correct 118 ms 19276 KB Output is correct
101 Correct 100 ms 16872 KB Output is correct
102 Correct 94 ms 16000 KB Output is correct
103 Correct 138 ms 15744 KB Output is correct
104 Correct 63 ms 15996 KB Output is correct
105 Correct 118 ms 26488 KB Output is correct
106 Correct 58 ms 15900 KB Output is correct
107 Correct 61 ms 15832 KB Output is correct
108 Correct 129 ms 31232 KB Output is correct
109 Correct 61 ms 16048 KB Output is correct
110 Correct 143 ms 31592 KB Output is correct
111 Correct 104 ms 15032 KB Output is correct