답안 #516479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516479 2022-01-21T11:54:07 Z DJ035 Power Plant (JOI20_power) C++17
0 / 100
2 ms 3788 KB
#include <bits/stdc++.h>
#define MEM 111111
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll MOD = 1e9+7;
const ll INF = 2e14+7;
ll mul(ll a, ll b){
    return ((a*b)%MOD+MOD)%MOD;
}
ll add(ll a, ll b){
    return ((a+b)%MOD+MOD)%MOD;
}

ll t,n,m,q,k;
ll dp[MEM];
ll ans;
vector<ll> g[MEM];
string s;
ll DP(ll c, ll p){
    ll& ret = dp[c];
    if(ret!=-1) return ret;
    ll dsum=0, dmx=-INF;
    for(ll nt:g[c]){
        if(nt==p) continue;
        ll o=DP(nt, c);
        dsum += o;
        dmx = max(o, dmx);
    }
    ll ct=(ll)(s[c-1]-'0');
    ret = max(dsum-ct, ct);
    ans = max({ans, dmx+ct, dsum-ct});
    return ret;
}
signed main(){
    sanic; cin.tie(0); cout.tie(0);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i=1; i<n; i++){
        ll q1,q2;
        cin >> q1 >> q2;
        g[q1].pb(q2);
        g[q2].pb(q1);
    }
    cin >> s;
    DP(1, -1);
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3788 KB Output isn't correct
2 Halted 0 ms 0 KB -