제출 #514856

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
5148562022-01-18 15:28:27ACE_Power Plant (JOI20_power)C++14
100 / 100
284 ms28860 KiB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int t, dp[maxn], n, ans;
vector<int> V[maxn];
string s;
void dfs(int u,int p) {
int m = 0, all = 0;
for(int i = 0; i < V[u].size(); i++) {
if(V[u][i] == p) continue;
dfs(V[u][i], u);
all += dp[V[u][i]];
m = max(m, dp[V[u][i]]);
}
dp[u] = max(m - (s[u] == '1'), 0 + (s[u] == '1'));
dp[u] = max(dp[u], all - (s[u] == '1'));
ans = max(ans, m + (s[u] == '1')); ans = max(ans, dp[u]);
}
main(){
cin >> n;
for(int i = 2; i <= n; i++) {
int u,v;
cin >> u >> v;
V[u].push_back(v); V[v].push_back(u);
}
cin >> s; s = '#' + s;
dfs(1, 0);
cout << max(ans, dp[1]);
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

컴파일 시 표준 에러 (stderr) 메시지

power.cpp: In function 'void dfs(int, int)':
power.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
power.cpp: At global scope:
power.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...