Submission #955662

# Submission time Handle Problem Language Result Execution time Memory
955662 2024-03-31T09:38:55 Z vjudge1 Power Plant (JOI20_power) C++17
0 / 100
3 ms 9564 KB
#include<bits/stdc++.h>
using namespace std;
int n;
int x,y;
vector<int>a[300000];
int ktr[300000];
int f[300000];
string s;
int asw=0;
void sol(int i){
    ktr[i]=1;
    int o=0;
    int mx=0;
    for(int u:a[i]){
        if(!ktr[u]){
            sol(u);
            f[i]+=f[u];
        }
    }
    if(s[i]=='1'){
        f[i]++;
        asw++;
        if(f[i]>2){
            f[i]=2;
            asw--;
        }
    }
}
int main(){
    cin >>n;
    for(int i=1;i<n;i++){
        cin >>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    cin >>s;
    s=" "+s;
    sol(1);
    cout<<asw;
}
/*
5 4
2 1 3
1 3 5 6
1 1 2 4
2 2 3
*/

Compilation message

power.cpp: In function 'void sol(int)':
power.cpp:12:9: warning: unused variable 'o' [-Wunused-variable]
   12 |     int o=0;
      |         ^
power.cpp:13:9: warning: unused variable 'mx' [-Wunused-variable]
   13 |     int mx=0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 3 ms 9564 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Incorrect 3 ms 9564 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 3 ms 9564 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Incorrect 3 ms 9564 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 3 ms 9564 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Incorrect 3 ms 9564 KB Output isn't correct
6 Halted 0 ms 0 KB -