답안 #1120082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1120082 2024-11-28T00:45:16 Z irmuun Power Plant (JOI20_power) C++17
47 / 100
1500 ms 16016 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int N=2e5+5;

int n,ans=0;
vector<int>g[N];
string s;
int dp[N],e[N];

void dfs(int x,int p){
    e[x]=(s[x]=='1'?1:0);
    dp[x]=0;
    for(int y:g[x]){
        if(y!=p){
            dfs(y,x);
            dp[x]+=dp[y];
        }
    }
    dp[x]=max(dp[x]-e[x],e[x]);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            dfs(i,i);
            for(int j:g[i]){
                ans=max(ans,dp[j]+1);
            }
            ans=max(ans,dp[i]);
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6564 KB Output is correct
3 Correct 4 ms 6496 KB Output is correct
4 Correct 3 ms 6496 KB Output is correct
5 Correct 3 ms 6496 KB Output is correct
6 Correct 3 ms 6496 KB Output is correct
7 Correct 2 ms 6496 KB Output is correct
8 Correct 3 ms 6496 KB Output is correct
9 Correct 3 ms 6728 KB Output is correct
10 Correct 3 ms 6524 KB Output is correct
11 Correct 4 ms 6520 KB Output is correct
12 Correct 3 ms 6552 KB Output is correct
13 Correct 2 ms 6496 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 3 ms 6496 KB Output is correct
16 Correct 3 ms 6496 KB Output is correct
17 Correct 3 ms 6496 KB Output is correct
18 Correct 2 ms 6496 KB Output is correct
19 Correct 2 ms 6564 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6564 KB Output is correct
3 Correct 4 ms 6496 KB Output is correct
4 Correct 3 ms 6496 KB Output is correct
5 Correct 3 ms 6496 KB Output is correct
6 Correct 3 ms 6496 KB Output is correct
7 Correct 2 ms 6496 KB Output is correct
8 Correct 3 ms 6496 KB Output is correct
9 Correct 3 ms 6728 KB Output is correct
10 Correct 3 ms 6524 KB Output is correct
11 Correct 4 ms 6520 KB Output is correct
12 Correct 3 ms 6552 KB Output is correct
13 Correct 2 ms 6496 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 3 ms 6496 KB Output is correct
16 Correct 3 ms 6496 KB Output is correct
17 Correct 3 ms 6496 KB Output is correct
18 Correct 2 ms 6496 KB Output is correct
19 Correct 2 ms 6564 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6496 KB Output is correct
22 Correct 36 ms 6640 KB Output is correct
23 Correct 33 ms 6496 KB Output is correct
24 Correct 29 ms 6576 KB Output is correct
25 Correct 19 ms 6496 KB Output is correct
26 Correct 12 ms 6660 KB Output is correct
27 Correct 6 ms 6644 KB Output is correct
28 Correct 3 ms 6496 KB Output is correct
29 Correct 58 ms 6804 KB Output is correct
30 Correct 34 ms 6752 KB Output is correct
31 Correct 34 ms 6496 KB Output is correct
32 Correct 19 ms 6640 KB Output is correct
33 Correct 35 ms 6648 KB Output is correct
34 Correct 20 ms 6484 KB Output is correct
35 Correct 12 ms 6640 KB Output is correct
36 Correct 6 ms 6652 KB Output is correct
37 Correct 24 ms 6484 KB Output is correct
38 Correct 18 ms 6484 KB Output is correct
39 Correct 49 ms 6820 KB Output is correct
40 Correct 22 ms 6484 KB Output is correct
41 Correct 15 ms 6484 KB Output is correct
42 Correct 20 ms 6484 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 40 ms 6484 KB Output is correct
45 Correct 32 ms 6484 KB Output is correct
46 Correct 21 ms 6484 KB Output is correct
47 Correct 12 ms 6564 KB Output is correct
48 Correct 44 ms 6824 KB Output is correct
49 Correct 44 ms 6756 KB Output is correct
50 Correct 45 ms 6496 KB Output is correct
51 Correct 44 ms 6484 KB Output is correct
52 Correct 36 ms 6484 KB Output is correct
53 Correct 27 ms 6700 KB Output is correct
54 Correct 40 ms 6484 KB Output is correct
55 Correct 35 ms 6484 KB Output is correct
56 Correct 4 ms 6484 KB Output is correct
57 Correct 4 ms 6624 KB Output is correct
58 Correct 22 ms 6700 KB Output is correct
59 Correct 22 ms 6676 KB Output is correct
60 Correct 3 ms 6908 KB Output is correct
61 Correct 3 ms 6484 KB Output is correct
62 Correct 3 ms 6740 KB Output is correct
63 Correct 31 ms 6644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6564 KB Output is correct
3 Correct 4 ms 6496 KB Output is correct
4 Correct 3 ms 6496 KB Output is correct
5 Correct 3 ms 6496 KB Output is correct
6 Correct 3 ms 6496 KB Output is correct
7 Correct 2 ms 6496 KB Output is correct
8 Correct 3 ms 6496 KB Output is correct
9 Correct 3 ms 6728 KB Output is correct
10 Correct 3 ms 6524 KB Output is correct
11 Correct 4 ms 6520 KB Output is correct
12 Correct 3 ms 6552 KB Output is correct
13 Correct 2 ms 6496 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 3 ms 6496 KB Output is correct
16 Correct 3 ms 6496 KB Output is correct
17 Correct 3 ms 6496 KB Output is correct
18 Correct 2 ms 6496 KB Output is correct
19 Correct 2 ms 6564 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6496 KB Output is correct
22 Correct 36 ms 6640 KB Output is correct
23 Correct 33 ms 6496 KB Output is correct
24 Correct 29 ms 6576 KB Output is correct
25 Correct 19 ms 6496 KB Output is correct
26 Correct 12 ms 6660 KB Output is correct
27 Correct 6 ms 6644 KB Output is correct
28 Correct 3 ms 6496 KB Output is correct
29 Correct 58 ms 6804 KB Output is correct
30 Correct 34 ms 6752 KB Output is correct
31 Correct 34 ms 6496 KB Output is correct
32 Correct 19 ms 6640 KB Output is correct
33 Correct 35 ms 6648 KB Output is correct
34 Correct 20 ms 6484 KB Output is correct
35 Correct 12 ms 6640 KB Output is correct
36 Correct 6 ms 6652 KB Output is correct
37 Correct 24 ms 6484 KB Output is correct
38 Correct 18 ms 6484 KB Output is correct
39 Correct 49 ms 6820 KB Output is correct
40 Correct 22 ms 6484 KB Output is correct
41 Correct 15 ms 6484 KB Output is correct
42 Correct 20 ms 6484 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 40 ms 6484 KB Output is correct
45 Correct 32 ms 6484 KB Output is correct
46 Correct 21 ms 6484 KB Output is correct
47 Correct 12 ms 6564 KB Output is correct
48 Correct 44 ms 6824 KB Output is correct
49 Correct 44 ms 6756 KB Output is correct
50 Correct 45 ms 6496 KB Output is correct
51 Correct 44 ms 6484 KB Output is correct
52 Correct 36 ms 6484 KB Output is correct
53 Correct 27 ms 6700 KB Output is correct
54 Correct 40 ms 6484 KB Output is correct
55 Correct 35 ms 6484 KB Output is correct
56 Correct 4 ms 6484 KB Output is correct
57 Correct 4 ms 6624 KB Output is correct
58 Correct 22 ms 6700 KB Output is correct
59 Correct 22 ms 6676 KB Output is correct
60 Correct 3 ms 6908 KB Output is correct
61 Correct 3 ms 6484 KB Output is correct
62 Correct 3 ms 6740 KB Output is correct
63 Correct 31 ms 6644 KB Output is correct
64 Execution timed out 1549 ms 16016 KB Time limit exceeded
65 Halted 0 ms 0 KB -