# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558075 | groshi | Power Plant (JOI20_power) | C++17 | 172 ms | 25452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
using namespace std;
struct wi{
vector<int> Q;
}*w;
int wynik=0;
string s;
int dfs(int x,int ojc)
{
int ile=0;
for(int i=0;i<w[x].Q.size();i++)
{
int pom=w[x].Q[i];
if(pom==ojc)
continue;
int k=dfs(pom,x);
ile+=k;
if(s[x-1]=='1')
wynik=max(wynik,k+1);
}
if(s[x-1]=='1')
ile=max(ile-1,1);
wynik=max(wynik,ile);
return ile;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,x,y;
cin>>n;
w=new wi[n+3];
for(int i=1;i<n;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
w[y].Q.push_back(x);
}
cin>>s;
int k=dfs(1,0);
cout<<wynik;
return 0;
}
Compilation message (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... |