답안 #307498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307498 2020-09-28T11:33:59 Z asifthegreat Power Plant (JOI20_power) C++14
0 / 100
6 ms 7424 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5;

vector<int>graph[N];
int dp[N];
string s = ":";
int res = 0;

void dfs(int v, int par){
    int mx = 0;
    for(auto c : graph[v]){
        if(c == par) continue;
        dfs(c, v);
        dp[v] += dp[c];
        mx = max(mx, dp[c]);
    }
    if(s[v] == '1') res = max(res, 1+mx);
    else res = max(res, dp[v]);
    dp[v] -= s[v]-'0';
    if(dp[v] <= 0 && s[v] == '1') dp[v] = 1;
    res = max(res, dp[v]);
}
int main(){

  int n;
  cin >> n;
  for(int i = 1; i < n;i++){
    int a,b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  string t;
  cin >> t;
  dfs(1, 0);
  cout << res << endl;

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -