# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
849772 |
2023-09-15T10:27:11 Z |
Abito |
Power Plant (JOI20_power) |
C++14 |
|
2 ms |
6492 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int n,dp[N];
vector<int> adj[N];
bool a[N];
int rec(int node,int p){
//int s=bool(p);
dp[node]=0;
for (auto u:adj[node]) if (u!=p) dp[node]+=rec(u,node);
if (adj[node].size()<=1) dp[node]+=a[node];
else dp[node]-=a[node];
return dp[node]=max(dp[node],(int)a[node]);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<n;i++){
int x,y;cin>>x>>y;
adj[x].pb(y);adj[y].pb(x);
}for (int i=1;i<=n;i++){char c;cin>>c;a[i]=c-'0';}
cout<<rec(1,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |