답안 #735778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735778 2023-05-04T16:07:32 Z alexdd Power Plant (JOI20_power) C++17
100 / 100
206 ms 32252 KB
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n;
vector<int> con[200005];
int dp[200005][2];
bool iss[200005];
int mxm=0;
void dfs(int nod, int par)
{
    dp[nod][0]=0;
    dp[nod][1]=0;
    int sum0=0, max1=0, max0=0;
    for(auto adj:con[nod])
    {
        if(adj!=par)
        {
            dfs(adj,nod);
            sum0 += dp[adj][0];
            max1 = max(max1, dp[adj][1]);
            max0 = max(max0, dp[adj][0]);
        }
    }
    if(iss[nod])
    {
        dp[nod][0] = max(1, sum0-1);
        dp[nod][1] = max0 + 1;///dp[nod][1] = max(dp[adj][0]) + 1
    }
    else
    {
        dp[nod][0] = sum0;
        dp[nod][1] = max1;///dp[nod][1] = max(dp[adj][1])
    }
    mxm = max(mxm, dp[nod][1]);
    mxm = max(mxm, dp[nod][0]);
    //cout<<nod<<"  "<<dp[nod][0]<<" "<<dp[nod][1]<<"    "<<iss[nod]<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        con[a].push_back(b);
        con[b].push_back(a);
    }
    int cnt1=0;
    char ch;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        if(ch=='1')
            iss[i]=1;
        else
            iss[i]=0;
        if(iss[i])
            cnt1++;
    }
    dfs(1,0);
    cout<<mxm;
    return 0;
}
/**

dp[nod][0] = scorul maxim pe care il putem obtine daca nu avem niciun nod "in-danger"
dp[nod][1] = scorul maxim pe care il putem obtine daca avem un nod "in-danger"


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4964 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4964 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
22 Correct 5 ms 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5112 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 5 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5048 KB Output is correct
34 Correct 3 ms 5040 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 4 ms 5092 KB Output is correct
43 Correct 4 ms 5048 KB Output is correct
44 Correct 4 ms 5088 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 4 ms 5040 KB Output is correct
47 Correct 3 ms 5096 KB Output is correct
48 Correct 5 ms 5172 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 4 ms 5076 KB Output is correct
51 Correct 4 ms 5168 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5076 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4964 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
22 Correct 5 ms 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5112 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 5 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5048 KB Output is correct
34 Correct 3 ms 5040 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 4 ms 5092 KB Output is correct
43 Correct 4 ms 5048 KB Output is correct
44 Correct 4 ms 5088 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 4 ms 5040 KB Output is correct
47 Correct 3 ms 5096 KB Output is correct
48 Correct 5 ms 5172 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 4 ms 5076 KB Output is correct
51 Correct 4 ms 5168 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5076 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 125 ms 15864 KB Output is correct
65 Correct 158 ms 15816 KB Output is correct
66 Correct 130 ms 15868 KB Output is correct
67 Correct 134 ms 15744 KB Output is correct
68 Correct 184 ms 15852 KB Output is correct
69 Correct 127 ms 15816 KB Output is correct
70 Correct 132 ms 15848 KB Output is correct
71 Correct 162 ms 15860 KB Output is correct
72 Correct 140 ms 15868 KB Output is correct
73 Correct 153 ms 31024 KB Output is correct
74 Correct 206 ms 30932 KB Output is correct
75 Correct 145 ms 15660 KB Output is correct
76 Correct 146 ms 15668 KB Output is correct
77 Correct 178 ms 15748 KB Output is correct
78 Correct 163 ms 15624 KB Output is correct
79 Correct 142 ms 15840 KB Output is correct
80 Correct 162 ms 15732 KB Output is correct
81 Correct 149 ms 16080 KB Output is correct
82 Correct 116 ms 15944 KB Output is correct
83 Correct 165 ms 22024 KB Output is correct
84 Correct 177 ms 24460 KB Output is correct
85 Correct 164 ms 24172 KB Output is correct
86 Correct 169 ms 17408 KB Output is correct
87 Correct 159 ms 16760 KB Output is correct
88 Correct 144 ms 17100 KB Output is correct
89 Correct 132 ms 17228 KB Output is correct
90 Correct 133 ms 16980 KB Output is correct
91 Correct 180 ms 17192 KB Output is correct
92 Correct 151 ms 17620 KB Output is correct
93 Correct 124 ms 20532 KB Output is correct
94 Correct 165 ms 22520 KB Output is correct
95 Correct 127 ms 21016 KB Output is correct
96 Correct 131 ms 18904 KB Output is correct
97 Correct 119 ms 17012 KB Output is correct
98 Correct 140 ms 16432 KB Output is correct
99 Correct 133 ms 16144 KB Output is correct
100 Correct 134 ms 20020 KB Output is correct
101 Correct 156 ms 17604 KB Output is correct
102 Correct 132 ms 16576 KB Output is correct
103 Correct 143 ms 16436 KB Output is correct
104 Correct 78 ms 16564 KB Output is correct
105 Correct 182 ms 27148 KB Output is correct
106 Correct 79 ms 16416 KB Output is correct
107 Correct 89 ms 16380 KB Output is correct
108 Correct 144 ms 31884 KB Output is correct
109 Correct 88 ms 16616 KB Output is correct
110 Correct 141 ms 32252 KB Output is correct
111 Correct 120 ms 15748 KB Output is correct