답안 #677575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677575 2023-01-03T19:04:27 Z MarcuMihai Power Plant (JOI20_power) C++14
100 / 100
237 ms 31380 KB
#include <bits/stdc++.h>

using namespace std;

int n;
vector <int> v[200005];
int dp[200005];
int gen[200005];
int maxim=0;

void DFS(int nod, int tata)
{
    if(gen[nod]==1)
        dp[nod]=1;
    int mxx=0;
    int sum=0;
    for(int x=0; x<v[nod].size(); ++x)
    {
        int fiu=v[nod][x];
        if(fiu!=tata)
        {
            DFS(fiu, nod);
            mxx=max(mxx, dp[fiu]);
            if(gen[nod]==1)
                maxim=max(maxim, mxx+1);
            sum+=dp[fiu];
        }
    }
    if(gen[nod]==1)
        sum-=1;
    dp[nod]=max(dp[nod], sum);
    maxim=max(maxim, dp[nod]);
}


int main()
{
    cin>>n;
    for(int i=1; i<n; ++i)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1; i<=n; ++i)
    {
        char x;
        cin>>x;
        if(x=='1')
            gen[i]=1;
    }
    DFS(1,0);
    cout<<maxim;

    return 0;
}

Compilation message

power.cpp: In function 'void DFS(int, int)':
power.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int x=0; x<v[nod].size(); ++x)
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5004 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4920 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5000 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 4 ms 5000 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5004 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4920 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5000 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 4 ms 5000 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5020 KB Output is correct
24 Correct 5 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5016 KB Output is correct
28 Correct 4 ms 5016 KB Output is correct
29 Correct 4 ms 5144 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 6 ms 5012 KB Output is correct
33 Correct 4 ms 5016 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5012 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5136 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 4 ms 5072 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5012 KB Output is correct
48 Correct 4 ms 5140 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 4 ms 5076 KB Output is correct
51 Correct 4 ms 5012 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5148 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5072 KB Output is correct
56 Correct 4 ms 5024 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5032 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 4 ms 5016 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5004 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4920 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5000 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 4 ms 5000 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5020 KB Output is correct
24 Correct 5 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5016 KB Output is correct
28 Correct 4 ms 5016 KB Output is correct
29 Correct 4 ms 5144 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 6 ms 5012 KB Output is correct
33 Correct 4 ms 5016 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5012 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5136 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 4 ms 5072 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5012 KB Output is correct
48 Correct 4 ms 5140 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 4 ms 5076 KB Output is correct
51 Correct 4 ms 5012 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5148 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5072 KB Output is correct
56 Correct 4 ms 5024 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 4 ms 5032 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 4 ms 5016 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5072 KB Output is correct
64 Correct 194 ms 15616 KB Output is correct
65 Correct 226 ms 15648 KB Output is correct
66 Correct 197 ms 15628 KB Output is correct
67 Correct 202 ms 15592 KB Output is correct
68 Correct 201 ms 15636 KB Output is correct
69 Correct 191 ms 15640 KB Output is correct
70 Correct 196 ms 15748 KB Output is correct
71 Correct 195 ms 15632 KB Output is correct
72 Correct 199 ms 15048 KB Output is correct
73 Correct 228 ms 30812 KB Output is correct
74 Correct 218 ms 30656 KB Output is correct
75 Correct 197 ms 15632 KB Output is correct
76 Correct 192 ms 15544 KB Output is correct
77 Correct 203 ms 15516 KB Output is correct
78 Correct 210 ms 15612 KB Output is correct
79 Correct 204 ms 15524 KB Output is correct
80 Correct 192 ms 15520 KB Output is correct
81 Correct 184 ms 15900 KB Output is correct
82 Correct 188 ms 15744 KB Output is correct
83 Correct 206 ms 21688 KB Output is correct
84 Correct 213 ms 24364 KB Output is correct
85 Correct 205 ms 23836 KB Output is correct
86 Correct 192 ms 17252 KB Output is correct
87 Correct 197 ms 16496 KB Output is correct
88 Correct 189 ms 16972 KB Output is correct
89 Correct 185 ms 16908 KB Output is correct
90 Correct 199 ms 16656 KB Output is correct
91 Correct 190 ms 16944 KB Output is correct
92 Correct 190 ms 17328 KB Output is correct
93 Correct 179 ms 20332 KB Output is correct
94 Correct 183 ms 22436 KB Output is correct
95 Correct 184 ms 20744 KB Output is correct
96 Correct 184 ms 18636 KB Output is correct
97 Correct 188 ms 16772 KB Output is correct
98 Correct 189 ms 16116 KB Output is correct
99 Correct 202 ms 15884 KB Output is correct
100 Correct 193 ms 19804 KB Output is correct
101 Correct 189 ms 17368 KB Output is correct
102 Correct 211 ms 16424 KB Output is correct
103 Correct 191 ms 16148 KB Output is correct
104 Correct 151 ms 15676 KB Output is correct
105 Correct 224 ms 26200 KB Output is correct
106 Correct 147 ms 16172 KB Output is correct
107 Correct 149 ms 16300 KB Output is correct
108 Correct 211 ms 30856 KB Output is correct
109 Correct 150 ms 15548 KB Output is correct
110 Correct 237 ms 31380 KB Output is correct
111 Correct 189 ms 15456 KB Output is correct