답안 #762946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762946 2023-06-22T01:38:16 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
197 ms 46744 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x, i) (1 & ((x) >> (i)))
#define MASK(x) (1LL << (x))
#define task "tnc"
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int mo = 998244353;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<int> G[maxn];
string s;
int re[maxn];
int dp[maxn];
int tong[maxn];
void dfs(int u, int pa)
{
    for (auto v : G[u])
    {
        if (v == pa)
            continue;
        dfs(v, u);
        dp[u] += dp[v];
        tong[u] += dp[v];
    }
    if (s[u] == '1')
        dp[u] = max(dp[u] - 1, 1);
}
int ans = 0;
void dfs_re(int u, int pa)
{
    if (pa != -1)
    {
        re[u] = re[pa] + tong[pa] - dp[u];
        if (s[pa] == '1')
        {
            re[u] = max(1, re[u] - 1);
        }
        ans = max(ans, re[u] + dp[u]);
        if (s[u] == '1')
        {
            ans = max(ans, 1);
        }
    }
    for (auto v : G[u])
    {
        if (v == pa)
            continue;
        dfs_re(v, u);
    }
}
signed main()
{
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
    cin >> s;
    s = ' ' + s;
    dfs(1, -1);
    ans = max(ans, dp[1]);
    dfs_re(1, -1);
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23824 KB Output is correct
2 Correct 13 ms 23820 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 14 ms 23828 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 12 ms 23820 KB Output is correct
13 Correct 13 ms 23820 KB Output is correct
14 Correct 15 ms 23764 KB Output is correct
15 Correct 12 ms 23820 KB Output is correct
16 Correct 16 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 13 ms 23820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23824 KB Output is correct
2 Correct 13 ms 23820 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 14 ms 23828 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 12 ms 23820 KB Output is correct
13 Correct 13 ms 23820 KB Output is correct
14 Correct 15 ms 23764 KB Output is correct
15 Correct 12 ms 23820 KB Output is correct
16 Correct 16 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 13 ms 23820 KB Output is correct
22 Correct 13 ms 23892 KB Output is correct
23 Correct 13 ms 23832 KB Output is correct
24 Correct 15 ms 23928 KB Output is correct
25 Correct 16 ms 23896 KB Output is correct
26 Correct 16 ms 23892 KB Output is correct
27 Correct 14 ms 23820 KB Output is correct
28 Correct 14 ms 23836 KB Output is correct
29 Correct 15 ms 23984 KB Output is correct
30 Correct 13 ms 24020 KB Output is correct
31 Correct 13 ms 23848 KB Output is correct
32 Correct 15 ms 23892 KB Output is correct
33 Correct 13 ms 23932 KB Output is correct
34 Correct 14 ms 23908 KB Output is correct
35 Correct 13 ms 23884 KB Output is correct
36 Correct 13 ms 23892 KB Output is correct
37 Correct 12 ms 23892 KB Output is correct
38 Correct 13 ms 23884 KB Output is correct
39 Correct 13 ms 23892 KB Output is correct
40 Correct 13 ms 23940 KB Output is correct
41 Correct 14 ms 23892 KB Output is correct
42 Correct 13 ms 23892 KB Output is correct
43 Correct 13 ms 23892 KB Output is correct
44 Correct 13 ms 23892 KB Output is correct
45 Correct 13 ms 23960 KB Output is correct
46 Correct 13 ms 23956 KB Output is correct
47 Correct 13 ms 23892 KB Output is correct
48 Correct 13 ms 24020 KB Output is correct
49 Correct 13 ms 24004 KB Output is correct
50 Correct 14 ms 23892 KB Output is correct
51 Correct 13 ms 23936 KB Output is correct
52 Correct 14 ms 23892 KB Output is correct
53 Correct 14 ms 23976 KB Output is correct
54 Correct 13 ms 23960 KB Output is correct
55 Correct 13 ms 23960 KB Output is correct
56 Correct 15 ms 23944 KB Output is correct
57 Correct 14 ms 24020 KB Output is correct
58 Correct 13 ms 23912 KB Output is correct
59 Correct 13 ms 23956 KB Output is correct
60 Correct 14 ms 24020 KB Output is correct
61 Correct 14 ms 23920 KB Output is correct
62 Correct 13 ms 24020 KB Output is correct
63 Correct 13 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23824 KB Output is correct
2 Correct 13 ms 23820 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 14 ms 23828 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 12 ms 23820 KB Output is correct
13 Correct 13 ms 23820 KB Output is correct
14 Correct 15 ms 23764 KB Output is correct
15 Correct 12 ms 23820 KB Output is correct
16 Correct 16 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 13 ms 23820 KB Output is correct
22 Correct 13 ms 23892 KB Output is correct
23 Correct 13 ms 23832 KB Output is correct
24 Correct 15 ms 23928 KB Output is correct
25 Correct 16 ms 23896 KB Output is correct
26 Correct 16 ms 23892 KB Output is correct
27 Correct 14 ms 23820 KB Output is correct
28 Correct 14 ms 23836 KB Output is correct
29 Correct 15 ms 23984 KB Output is correct
30 Correct 13 ms 24020 KB Output is correct
31 Correct 13 ms 23848 KB Output is correct
32 Correct 15 ms 23892 KB Output is correct
33 Correct 13 ms 23932 KB Output is correct
34 Correct 14 ms 23908 KB Output is correct
35 Correct 13 ms 23884 KB Output is correct
36 Correct 13 ms 23892 KB Output is correct
37 Correct 12 ms 23892 KB Output is correct
38 Correct 13 ms 23884 KB Output is correct
39 Correct 13 ms 23892 KB Output is correct
40 Correct 13 ms 23940 KB Output is correct
41 Correct 14 ms 23892 KB Output is correct
42 Correct 13 ms 23892 KB Output is correct
43 Correct 13 ms 23892 KB Output is correct
44 Correct 13 ms 23892 KB Output is correct
45 Correct 13 ms 23960 KB Output is correct
46 Correct 13 ms 23956 KB Output is correct
47 Correct 13 ms 23892 KB Output is correct
48 Correct 13 ms 24020 KB Output is correct
49 Correct 13 ms 24004 KB Output is correct
50 Correct 14 ms 23892 KB Output is correct
51 Correct 13 ms 23936 KB Output is correct
52 Correct 14 ms 23892 KB Output is correct
53 Correct 14 ms 23976 KB Output is correct
54 Correct 13 ms 23960 KB Output is correct
55 Correct 13 ms 23960 KB Output is correct
56 Correct 15 ms 23944 KB Output is correct
57 Correct 14 ms 24020 KB Output is correct
58 Correct 13 ms 23912 KB Output is correct
59 Correct 13 ms 23956 KB Output is correct
60 Correct 14 ms 24020 KB Output is correct
61 Correct 14 ms 23920 KB Output is correct
62 Correct 13 ms 24020 KB Output is correct
63 Correct 13 ms 23892 KB Output is correct
64 Correct 100 ms 33020 KB Output is correct
65 Correct 102 ms 33096 KB Output is correct
66 Correct 122 ms 33116 KB Output is correct
67 Correct 105 ms 33044 KB Output is correct
68 Correct 102 ms 33064 KB Output is correct
69 Correct 127 ms 33100 KB Output is correct
70 Correct 98 ms 33124 KB Output is correct
71 Correct 97 ms 33068 KB Output is correct
72 Correct 103 ms 33096 KB Output is correct
73 Correct 130 ms 45640 KB Output is correct
74 Correct 155 ms 45656 KB Output is correct
75 Correct 105 ms 32940 KB Output is correct
76 Correct 109 ms 33004 KB Output is correct
77 Correct 131 ms 33024 KB Output is correct
78 Correct 113 ms 32916 KB Output is correct
79 Correct 132 ms 33060 KB Output is correct
80 Correct 100 ms 32932 KB Output is correct
81 Correct 86 ms 33436 KB Output is correct
82 Correct 97 ms 33160 KB Output is correct
83 Correct 145 ms 38176 KB Output is correct
84 Correct 143 ms 40460 KB Output is correct
85 Correct 126 ms 40020 KB Output is correct
86 Correct 108 ms 34440 KB Output is correct
87 Correct 180 ms 33792 KB Output is correct
88 Correct 118 ms 34316 KB Output is correct
89 Correct 105 ms 34336 KB Output is correct
90 Correct 104 ms 34120 KB Output is correct
91 Correct 107 ms 34372 KB Output is correct
92 Correct 103 ms 34620 KB Output is correct
93 Correct 142 ms 37228 KB Output is correct
94 Correct 99 ms 38904 KB Output is correct
95 Correct 109 ms 37516 KB Output is correct
96 Correct 119 ms 35596 KB Output is correct
97 Correct 104 ms 34080 KB Output is correct
98 Correct 101 ms 33608 KB Output is correct
99 Correct 101 ms 33392 KB Output is correct
100 Correct 132 ms 36632 KB Output is correct
101 Correct 125 ms 34572 KB Output is correct
102 Correct 116 ms 33788 KB Output is correct
103 Correct 154 ms 33644 KB Output is correct
104 Correct 64 ms 32300 KB Output is correct
105 Correct 131 ms 42484 KB Output is correct
106 Correct 66 ms 33136 KB Output is correct
107 Correct 94 ms 33120 KB Output is correct
108 Correct 155 ms 46396 KB Output is correct
109 Correct 73 ms 32340 KB Output is correct
110 Correct 197 ms 46744 KB Output is correct
111 Correct 96 ms 32912 KB Output is correct