# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
788017 | YassineBenYounes | Power Plant (JOI20_power) | C++17 | 196 ms | 30300 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define vii vector<pii>
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = 3e5+5;
const ll mod = 1e9+7;
vector<int> graph[mx];
string s;
int dp_down[mx];
int ans = 0;
void dfs(int node, int p){
int l = 0, sum = 0;
for(int adj : graph[node]){
if(adj == p)continue;
dfs(adj ,node);
sum += dp_down[adj];
l = max(l, dp_down[adj]);
}
int k = (s[node] == '1');
sum -= k;
dp_down[node] = max(dp_down[node], k);
dp_down[node] = max(dp_down[node], sum);
ans = max(ans, l+k);
ans = max(ans, dp_down[node]);
}
void runcase(){
int n;cin >> n;
for(int i = 0; i < n-1;i++){
int a, b;cin >> a >> b;
graph[a].pb(b);
graph[b].pb(a);
}
cin >> s;
s = "Y" + s;
dfs(1, 1);
cout << ans << endl;
}
int main(){
int t;
//cin >> t;
t = 1;
while(t--){
runcase();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |