답안 #955528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955528 2024-03-30T19:51:47 Z HorizonWest Power Plant (JOI20_power) C++17
100 / 100
110 ms 25488 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define db double
#define ll __int128
#define int long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;

const int Max = 1e6 + 7, Inf = 1e9 + 7;

void print(bool x) { cout << (x ? "YES" : "NO") << endl; }

string tostring (__int128 x)
{
    string ans = "";
    while(x > 0)
    {
        ans += (x % 10 + '0');
        x /= 10;
    }
    reverse(all(ans));
    return ans;
}

vector <vector<int>> v;
string s; int ans;

int dfs(int node, int parent)
{
    int sum = 0, me = s[node] - '0';
    for(auto& u : v[node]) if(u != parent)
    {
        int w = dfs(u, node); 
        sum += w; ans = max(ans, w + me);
    }

    sum = sum - me;
    sum = max(sum, me);
    ans = max(ans, sum);
    return sum;
}

void solve()
{
    int n; cin >> n; 
    v.assign(n+1, vector <int> ());
    for(int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b; a--; b--;
        v[a].pb(b); v[b].pb(a); 
    }

    cin >> s;

    for(int i= 0; i < n; i++)
        ans += (s[i] - '0');

    ans = min(ans, 2LL); dfs(0, -1);

    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int Q = 1; //cin >> Q;

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 804 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 804 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 73 ms 15576 KB Output is correct
65 Correct 69 ms 15508 KB Output is correct
66 Correct 84 ms 15668 KB Output is correct
67 Correct 73 ms 15520 KB Output is correct
68 Correct 71 ms 15632 KB Output is correct
69 Correct 66 ms 15756 KB Output is correct
70 Correct 69 ms 15592 KB Output is correct
71 Correct 71 ms 15520 KB Output is correct
72 Correct 77 ms 15772 KB Output is correct
73 Correct 82 ms 24572 KB Output is correct
74 Correct 89 ms 24468 KB Output is correct
75 Correct 70 ms 16696 KB Output is correct
76 Correct 82 ms 16764 KB Output is correct
77 Correct 79 ms 15520 KB Output is correct
78 Correct 74 ms 15588 KB Output is correct
79 Correct 68 ms 15508 KB Output is correct
80 Correct 73 ms 15492 KB Output is correct
81 Correct 76 ms 15424 KB Output is correct
82 Correct 63 ms 15560 KB Output is correct
83 Correct 79 ms 19428 KB Output is correct
84 Correct 79 ms 21152 KB Output is correct
85 Correct 76 ms 20892 KB Output is correct
86 Correct 72 ms 16528 KB Output is correct
87 Correct 68 ms 16016 KB Output is correct
88 Correct 68 ms 16076 KB Output is correct
89 Correct 70 ms 16284 KB Output is correct
90 Correct 68 ms 16120 KB Output is correct
91 Correct 65 ms 16244 KB Output is correct
92 Correct 70 ms 16512 KB Output is correct
93 Correct 64 ms 18120 KB Output is correct
94 Correct 71 ms 19400 KB Output is correct
95 Correct 81 ms 18884 KB Output is correct
96 Correct 68 ms 17128 KB Output is correct
97 Correct 61 ms 15852 KB Output is correct
98 Correct 66 ms 15696 KB Output is correct
99 Correct 67 ms 15664 KB Output is correct
100 Correct 65 ms 17792 KB Output is correct
101 Correct 64 ms 16140 KB Output is correct
102 Correct 62 ms 15712 KB Output is correct
103 Correct 73 ms 15772 KB Output is correct
104 Correct 47 ms 16064 KB Output is correct
105 Correct 80 ms 22000 KB Output is correct
106 Correct 43 ms 16068 KB Output is correct
107 Correct 52 ms 15868 KB Output is correct
108 Correct 94 ms 24980 KB Output is correct
109 Correct 44 ms 16064 KB Output is correct
110 Correct 110 ms 25488 KB Output is correct
111 Correct 76 ms 15424 KB Output is correct