답안 #955832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955832 2024-03-31T14:04:50 Z Yang8on Power Plant (JOI20_power) C++14
100 / 100
121 ms 28844 KB
#include <bits/stdc++.h>
#define gsn "Power Plant"
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r) (rng);
}

const int maxn = 200005;

int n, ans;
int dp[maxn];
string s;
vector<int> o[maxn];

void dfs(int u, int par)
{
    int sum = 0, mx = 0;
    for(int v : o[u])
    {
        if(v == par) continue;
        dfs(v, u);

        sum += dp[v], mx = max(mx, dp[v]);
    }

    ans = max({ ans, sum - (s[u] == '1'), mx + (s[u] == '1') });
    dp[u] = max({ (int)(s[u] == '1'), sum - (s[u] == '1'), mx - (s[u] == '1') });
}

void solve()
{
    cin >> n;
    fi(i, 1, n - 1)
    {
        int u, v;
        cin >> u >> v;

        o[u].push_back(v);
        o[v].push_back(u);
    }

    cin >> s, s = ' ' + s;

    dfs(1, -1);

    cout << ans ;
}


int main()
{
    if(fopen(gsn".inp", "r"))
    {
        freopen(gsn".inp", "r", stdin);
        freopen(gsn".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int nTest = 1;
//    cin >> nTest;

    while(nTest --)
    {
        solve();
    }




    /// ------------------check time!-----------------///
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(gsn".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
power.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(gsn".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 5160 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 5160 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5464 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5180 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5464 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5176 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5212 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 2 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5244 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5208 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 2 ms 5208 KB Output is correct
56 Correct 3 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5208 KB Output is correct
59 Correct 2 ms 5208 KB Output is correct
60 Correct 2 ms 5208 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5208 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 5160 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5464 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5180 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5464 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5176 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5212 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 2 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5244 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5208 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 2 ms 5208 KB Output is correct
56 Correct 3 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5208 KB Output is correct
59 Correct 2 ms 5208 KB Output is correct
60 Correct 2 ms 5208 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5208 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 91 ms 15316 KB Output is correct
65 Correct 61 ms 15212 KB Output is correct
66 Correct 69 ms 15344 KB Output is correct
67 Correct 68 ms 15176 KB Output is correct
68 Correct 99 ms 15192 KB Output is correct
69 Correct 71 ms 15308 KB Output is correct
70 Correct 62 ms 15320 KB Output is correct
71 Correct 66 ms 15232 KB Output is correct
72 Correct 86 ms 15300 KB Output is correct
73 Correct 80 ms 27760 KB Output is correct
74 Correct 87 ms 27900 KB Output is correct
75 Correct 66 ms 14996 KB Output is correct
76 Correct 109 ms 15020 KB Output is correct
77 Correct 65 ms 15072 KB Output is correct
78 Correct 65 ms 15048 KB Output is correct
79 Correct 84 ms 15312 KB Output is correct
80 Correct 64 ms 15056 KB Output is correct
81 Correct 57 ms 15660 KB Output is correct
82 Correct 61 ms 15244 KB Output is correct
83 Correct 97 ms 20432 KB Output is correct
84 Correct 87 ms 22356 KB Output is correct
85 Correct 78 ms 22236 KB Output is correct
86 Correct 65 ms 16548 KB Output is correct
87 Correct 121 ms 15996 KB Output is correct
88 Correct 80 ms 16564 KB Output is correct
89 Correct 68 ms 16348 KB Output is correct
90 Correct 62 ms 16176 KB Output is correct
91 Correct 60 ms 16580 KB Output is correct
92 Correct 69 ms 16824 KB Output is correct
93 Correct 70 ms 19100 KB Output is correct
94 Correct 77 ms 21024 KB Output is correct
95 Correct 67 ms 19680 KB Output is correct
96 Correct 89 ms 17712 KB Output is correct
97 Correct 74 ms 16336 KB Output is correct
98 Correct 64 ms 15876 KB Output is correct
99 Correct 63 ms 15564 KB Output is correct
100 Correct 92 ms 18640 KB Output is correct
101 Correct 65 ms 16736 KB Output is correct
102 Correct 60 ms 16032 KB Output is correct
103 Correct 61 ms 15856 KB Output is correct
104 Correct 63 ms 16068 KB Output is correct
105 Correct 80 ms 24544 KB Output is correct
106 Correct 50 ms 16068 KB Output is correct
107 Correct 46 ms 16064 KB Output is correct
108 Correct 90 ms 28624 KB Output is correct
109 Correct 53 ms 16072 KB Output is correct
110 Correct 86 ms 28844 KB Output is correct
111 Correct 57 ms 15072 KB Output is correct