답안 #518691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518691 2022-01-24T12:33:15 Z cig32 Power Plant (JOI20_power) C++17
47 / 100
1500 ms 17760 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
 
vector<int> adj[MAXN];
char c[MAXN];
int dpf(int node, int prev) {
  int sum = 0, mx = 0;
  for(int x: adj[node]) {
    if(x != prev) {
      int d = dpf(x, node);
      sum += d;
      mx = max(mx, d);
    }
  }
  if(prev == -1) {
    return max(mx + 1, sum - 1);
  }
  if(c[node] == '0') {
    return sum;
  }
  else {
    return max(1ll, sum - 1);
  }
}
void solve(int tc) {
  int N;
  cin >> N;
  for(int i=1; i<N; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if(N == 1) {
    cout << "1\n"; return;
  }
  for(int i=1; i<=N; i++) cin >> c[i];
  int ans = 0;
  for(int i=1; i<=N; i++) {
    if(c[i] == '1') {
      ans = max(ans, dpf(i, -1));
    }
  }
  cout << ans << "\n";
}
 
int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 4 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 4 ms 7272 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 6 ms 7244 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7244 KB Output is correct
10 Correct 4 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 4 ms 7244 KB Output is correct
13 Correct 5 ms 7376 KB Output is correct
14 Correct 4 ms 7364 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 4 ms 7244 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7364 KB Output is correct
21 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 4 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 4 ms 7272 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 6 ms 7244 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7244 KB Output is correct
10 Correct 4 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 4 ms 7244 KB Output is correct
13 Correct 5 ms 7376 KB Output is correct
14 Correct 4 ms 7364 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 4 ms 7244 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7364 KB Output is correct
21 Correct 4 ms 7372 KB Output is correct
22 Correct 57 ms 7444 KB Output is correct
23 Correct 52 ms 7440 KB Output is correct
24 Correct 43 ms 7444 KB Output is correct
25 Correct 31 ms 7372 KB Output is correct
26 Correct 18 ms 7372 KB Output is correct
27 Correct 10 ms 7372 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 76 ms 7500 KB Output is correct
30 Correct 40 ms 7500 KB Output is correct
31 Correct 47 ms 7460 KB Output is correct
32 Correct 31 ms 7484 KB Output is correct
33 Correct 52 ms 7372 KB Output is correct
34 Correct 35 ms 7500 KB Output is correct
35 Correct 19 ms 7372 KB Output is correct
36 Correct 11 ms 7376 KB Output is correct
37 Correct 34 ms 7448 KB Output is correct
38 Correct 29 ms 7372 KB Output is correct
39 Correct 67 ms 7508 KB Output is correct
40 Correct 39 ms 7500 KB Output is correct
41 Correct 21 ms 7520 KB Output is correct
42 Correct 35 ms 7468 KB Output is correct
43 Correct 11 ms 7372 KB Output is correct
44 Correct 48 ms 7476 KB Output is correct
45 Correct 40 ms 7380 KB Output is correct
46 Correct 30 ms 7372 KB Output is correct
47 Correct 16 ms 7372 KB Output is correct
48 Correct 46 ms 7504 KB Output is correct
49 Correct 50 ms 7500 KB Output is correct
50 Correct 49 ms 7372 KB Output is correct
51 Correct 47 ms 7372 KB Output is correct
52 Correct 54 ms 7448 KB Output is correct
53 Correct 38 ms 7496 KB Output is correct
54 Correct 48 ms 7468 KB Output is correct
55 Correct 54 ms 7456 KB Output is correct
56 Correct 4 ms 7372 KB Output is correct
57 Correct 5 ms 7500 KB Output is correct
58 Correct 23 ms 7372 KB Output is correct
59 Correct 24 ms 7372 KB Output is correct
60 Correct 5 ms 7508 KB Output is correct
61 Correct 5 ms 7372 KB Output is correct
62 Correct 5 ms 7500 KB Output is correct
63 Correct 39 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 4 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 4 ms 7272 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 6 ms 7244 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7244 KB Output is correct
10 Correct 4 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 4 ms 7244 KB Output is correct
13 Correct 5 ms 7376 KB Output is correct
14 Correct 4 ms 7364 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 4 ms 7244 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7364 KB Output is correct
21 Correct 4 ms 7372 KB Output is correct
22 Correct 57 ms 7444 KB Output is correct
23 Correct 52 ms 7440 KB Output is correct
24 Correct 43 ms 7444 KB Output is correct
25 Correct 31 ms 7372 KB Output is correct
26 Correct 18 ms 7372 KB Output is correct
27 Correct 10 ms 7372 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 76 ms 7500 KB Output is correct
30 Correct 40 ms 7500 KB Output is correct
31 Correct 47 ms 7460 KB Output is correct
32 Correct 31 ms 7484 KB Output is correct
33 Correct 52 ms 7372 KB Output is correct
34 Correct 35 ms 7500 KB Output is correct
35 Correct 19 ms 7372 KB Output is correct
36 Correct 11 ms 7376 KB Output is correct
37 Correct 34 ms 7448 KB Output is correct
38 Correct 29 ms 7372 KB Output is correct
39 Correct 67 ms 7508 KB Output is correct
40 Correct 39 ms 7500 KB Output is correct
41 Correct 21 ms 7520 KB Output is correct
42 Correct 35 ms 7468 KB Output is correct
43 Correct 11 ms 7372 KB Output is correct
44 Correct 48 ms 7476 KB Output is correct
45 Correct 40 ms 7380 KB Output is correct
46 Correct 30 ms 7372 KB Output is correct
47 Correct 16 ms 7372 KB Output is correct
48 Correct 46 ms 7504 KB Output is correct
49 Correct 50 ms 7500 KB Output is correct
50 Correct 49 ms 7372 KB Output is correct
51 Correct 47 ms 7372 KB Output is correct
52 Correct 54 ms 7448 KB Output is correct
53 Correct 38 ms 7496 KB Output is correct
54 Correct 48 ms 7468 KB Output is correct
55 Correct 54 ms 7456 KB Output is correct
56 Correct 4 ms 7372 KB Output is correct
57 Correct 5 ms 7500 KB Output is correct
58 Correct 23 ms 7372 KB Output is correct
59 Correct 24 ms 7372 KB Output is correct
60 Correct 5 ms 7508 KB Output is correct
61 Correct 5 ms 7372 KB Output is correct
62 Correct 5 ms 7500 KB Output is correct
63 Correct 39 ms 7372 KB Output is correct
64 Execution timed out 1545 ms 17760 KB Time limit exceeded
65 Halted 0 ms 0 KB -