# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
788015 | 2023-07-19T16:15:07 Z | YassineBenYounes | Power Plant (JOI20_power) | C++17 | 4 ms | 7308 KB |
#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(){ init(); int t; //cin >> t; t = 1; while(t--){ runcase(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 7308 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 7308 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 7308 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |