답안 #803351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
803351 2023-08-03T04:15:59 Z khoquennguoiminhthuong Power Plant (JOI20_power) C++14
0 / 100
3 ms 5028 KB
#include <bits/stdc++.h>

using namespace std;
int n;
vector<int>g[200005];
string s;
int a[200005];
int dp[200005];
int ans=0;
void dfs(int u,int pa) {
    dp[u]=a[u];
    int sum1=0,sum2=0;
    for(auto v:g[u])
        if(v!=pa) {
            dfs(v,u);
            sum1=max(sum1,dp[v]);
            sum2+=dp[v];
        }
    ans=max(dp[u],sum1+a[u]);
    dp[u]=max(dp[u],sum2-a[u]);
    ans=max(ans,dp[u]);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1; i<n; i++) {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    cin>>s;
    for(int i=0; i<n; i++)if(s[i]=='1')a[i+1]=1;
    dfs(1,0);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 2 ms 5028 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 2 ms 5028 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 2 ms 5028 KB Output isn't correct
8 Halted 0 ms 0 KB -