답안 #394378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394378 2021-04-26T12:59:46 Z parsabahrami Power Plant (JOI20_power) C++17
100 / 100
254 ms 24504 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]);
    dp[v] = max(dp[v], sum - M[v]);
    dp[v] = max(dp[v], M[v]); 
    if (~p) ret = max(ret, dp[v] + M[p]);
}

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", max(ret, dp[rt]));
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
power.cpp:34:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         int u, v; scanf("%d%d", &u, &v);
      |                   ~~~~~^~~~~~~~~~~~~~~~
power.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("\n");
      |     ~~~~~^~~~~~
power.cpp:40:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |         char c; scanf("%c", &c);
      |                 ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4924 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 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 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 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 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4924 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 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 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 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 5068 KB Output is correct
23 Correct 4 ms 5016 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5084 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 5 ms 5068 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 6 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5052 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 6 ms 5052 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 4 ms 5128 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 5072 KB Output is correct
53 Correct 4 ms 5064 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5072 KB Output is correct
56 Correct 4 ms 5088 KB Output is correct
57 Correct 5 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 6 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5100 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 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4924 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 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 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 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 5068 KB Output is correct
23 Correct 4 ms 5016 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5084 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 5 ms 5068 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 6 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5052 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 6 ms 5052 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 4 ms 5128 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 5072 KB Output is correct
53 Correct 4 ms 5064 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5072 KB Output is correct
56 Correct 4 ms 5088 KB Output is correct
57 Correct 5 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 6 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5100 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 161 ms 12920 KB Output is correct
65 Correct 204 ms 12844 KB Output is correct
66 Correct 168 ms 12872 KB Output is correct
67 Correct 180 ms 12868 KB Output is correct
68 Correct 196 ms 12908 KB Output is correct
69 Correct 205 ms 12936 KB Output is correct
70 Correct 171 ms 13032 KB Output is correct
71 Correct 181 ms 12928 KB Output is correct
72 Correct 151 ms 12128 KB Output is correct
73 Correct 205 ms 23876 KB Output is correct
74 Correct 202 ms 21888 KB Output is correct
75 Correct 147 ms 12772 KB Output is correct
76 Correct 159 ms 12796 KB Output is correct
77 Correct 177 ms 12788 KB Output is correct
78 Correct 180 ms 12880 KB Output is correct
79 Correct 165 ms 12724 KB Output is correct
80 Correct 198 ms 12868 KB Output is correct
81 Correct 144 ms 13184 KB Output is correct
82 Correct 225 ms 12936 KB Output is correct
83 Correct 211 ms 16836 KB Output is correct
84 Correct 199 ms 16964 KB Output is correct
85 Correct 209 ms 18316 KB Output is correct
86 Correct 245 ms 13712 KB Output is correct
87 Correct 191 ms 14052 KB Output is correct
88 Correct 207 ms 13884 KB Output is correct
89 Correct 196 ms 14164 KB Output is correct
90 Correct 226 ms 13872 KB Output is correct
91 Correct 192 ms 14020 KB Output is correct
92 Correct 198 ms 14296 KB Output is correct
93 Correct 202 ms 17988 KB Output is correct
94 Correct 194 ms 16312 KB Output is correct
95 Correct 185 ms 17968 KB Output is correct
96 Correct 192 ms 16044 KB Output is correct
97 Correct 165 ms 13792 KB Output is correct
98 Correct 192 ms 13472 KB Output is correct
99 Correct 198 ms 13260 KB Output is correct
100 Correct 208 ms 15824 KB Output is correct
101 Correct 176 ms 14216 KB Output is correct
102 Correct 202 ms 13672 KB Output is correct
103 Correct 192 ms 13404 KB Output is correct
104 Correct 131 ms 12908 KB Output is correct
105 Correct 236 ms 24492 KB Output is correct
106 Correct 129 ms 13588 KB Output is correct
107 Correct 113 ms 13572 KB Output is correct
108 Correct 254 ms 24504 KB Output is correct
109 Correct 144 ms 12712 KB Output is correct
110 Correct 224 ms 24480 KB Output is correct
111 Correct 180 ms 12696 KB Output is correct