답안 #394376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394376 2021-04-26T12:57:28 Z AriaH Power Plant (JOI20_power) C++11
100 / 100
209 ms 27272 KB
/* There's someone in my head but it's not me */ 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
 
const int N = 2e5 + 10, MOD = 1e9 + 7;
int dp[N], pd[N], M[N], n, rt; vector<int> adj[N];
int ret = 0;
 
void DFS(int v, int p = -1) {
    for (int u : adj[v]) 
        if (u != p) DFS(u, v);
    int sum = 0;
    for (int u : adj[v]) 
        if (u != p) sum += dp[u];
    for (int u : adj[v])
        if (u != p) 
            dp[v] = max(dp[v], dp[u] - M[v]), ret = max(ret, dp[u] + M[v]);
    dp[v] = max(dp[v], sum - M[v]);
    dp[v] = max(dp[v], M[v]); 
    ret = max(ret, dp[v]);
    //printf("%d %d\n", v, dp[v]);
}
 
int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v; scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    scanf("\n");
    for (int i = 1; i <= n; i++) {
        char c; scanf("%c", &c);
        if (c - '0') M[i] = 1, rt = i;
    }
    DFS(rt);
    printf("%d\n", ret);
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
power.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         int u, v; scanf("%d%d", &u, &v);
      |                   ~~~~~^~~~~~~~~~~~~~~~
power.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("\n");
      |     ~~~~~^~~~~~
power.cpp:41:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         char c; scanf("%c", &c);
      |                 ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 5008 KB Output is correct
11 Correct 4 ms 5004 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4984 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 5008 KB Output is correct
11 Correct 4 ms 5004 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4984 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5012 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 5 ms 5012 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5216 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5024 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 5016 KB Output is correct
37 Correct 5 ms 5012 KB Output is correct
38 Correct 5 ms 5060 KB Output is correct
39 Correct 5 ms 5120 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 4 ms 5016 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5016 KB Output is correct
45 Correct 5 ms 5088 KB Output is correct
46 Correct 5 ms 5080 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5060 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5196 KB Output is correct
61 Correct 4 ms 5016 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 5008 KB Output is correct
11 Correct 4 ms 5004 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4984 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5012 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 5 ms 5012 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5216 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5024 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 5016 KB Output is correct
37 Correct 5 ms 5012 KB Output is correct
38 Correct 5 ms 5060 KB Output is correct
39 Correct 5 ms 5120 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 4 ms 5016 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5016 KB Output is correct
45 Correct 5 ms 5088 KB Output is correct
46 Correct 5 ms 5080 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5060 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5196 KB Output is correct
61 Correct 4 ms 5016 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 178 ms 15632 KB Output is correct
65 Correct 172 ms 15600 KB Output is correct
66 Correct 168 ms 15632 KB Output is correct
67 Correct 177 ms 15632 KB Output is correct
68 Correct 176 ms 15588 KB Output is correct
69 Correct 167 ms 15628 KB Output is correct
70 Correct 165 ms 15556 KB Output is correct
71 Correct 195 ms 15632 KB Output is correct
72 Correct 169 ms 14788 KB Output is correct
73 Correct 188 ms 26636 KB Output is correct
74 Correct 193 ms 24628 KB Output is correct
75 Correct 165 ms 15424 KB Output is correct
76 Correct 175 ms 15428 KB Output is correct
77 Correct 172 ms 15440 KB Output is correct
78 Correct 170 ms 15556 KB Output is correct
79 Correct 209 ms 15524 KB Output is correct
80 Correct 177 ms 15544 KB Output is correct
81 Correct 142 ms 15964 KB Output is correct
82 Correct 175 ms 15612 KB Output is correct
83 Correct 173 ms 19532 KB Output is correct
84 Correct 184 ms 19668 KB Output is correct
85 Correct 186 ms 21064 KB Output is correct
86 Correct 162 ms 16364 KB Output is correct
87 Correct 170 ms 16704 KB Output is correct
88 Correct 152 ms 16580 KB Output is correct
89 Correct 157 ms 16840 KB Output is correct
90 Correct 153 ms 16580 KB Output is correct
91 Correct 159 ms 16760 KB Output is correct
92 Correct 156 ms 16960 KB Output is correct
93 Correct 156 ms 20620 KB Output is correct
94 Correct 141 ms 18876 KB Output is correct
95 Correct 141 ms 20652 KB Output is correct
96 Correct 154 ms 18740 KB Output is correct
97 Correct 144 ms 16552 KB Output is correct
98 Correct 143 ms 16196 KB Output is correct
99 Correct 151 ms 15940 KB Output is correct
100 Correct 147 ms 18480 KB Output is correct
101 Correct 150 ms 16964 KB Output is correct
102 Correct 152 ms 16452 KB Output is correct
103 Correct 153 ms 16240 KB Output is correct
104 Correct 96 ms 15668 KB Output is correct
105 Correct 175 ms 27244 KB Output is correct
106 Correct 100 ms 16160 KB Output is correct
107 Correct 97 ms 16224 KB Output is correct
108 Correct 173 ms 27272 KB Output is correct
109 Correct 101 ms 15540 KB Output is correct
110 Correct 173 ms 27248 KB Output is correct
111 Correct 147 ms 15428 KB Output is correct