답안 #623054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623054 2022-08-05T06:42:01 Z Mahdi Power Plant (JOI20_power) C++17
0 / 100
3 ms 5032 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=2e5+5;
int n, dp[N], pd[N];
vector<int>g[N];
string s;

void dfs(const int &v, const int &p=-1){
    for(int u: g[v]){
        if(u!=p){
            dfs(u, v);
            pd[v]+=pd[u];
            dp[v]=max(dp[v], pd[u]+1);  
            dp[v]=max(dp[v], dp[u]);  
        }
    }
    if(s[v]=='1'){
        --pd[v];
        pd[v]=max(pd[v], 1);
    }
    dp[v]=max(dp[v], pd[v]);
}

int main(){
    ios_base::sync_with_stdio(0); cin.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;
    dfs(0);
    cout<<dp[0]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 5028 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 5032 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Incorrect 3 ms 5020 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 5028 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 5032 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Incorrect 3 ms 5020 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 5028 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 5032 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Incorrect 3 ms 5020 KB Output isn't correct
16 Halted 0 ms 0 KB -