Submission #569850

# Submission time Handle Problem Language Result Execution time Memory
569850 2022-05-27T23:03:21 Z OttoTheDino Power Plant (JOI20_power) C++17
0 / 100
3 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define len(a)                      (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;

const int mx=2e5;
vi adj[mx+1];
int ans;
string s;

bool dfs (int u, int p) {
    bool res = 0;
    for (int v :adj[u]){
       if (p==v) continue;
       res |= dfs (v, u);
    }
    if(s[u-1]=='1'){
       ans += 1-res;
       res = 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

        int n;cin>>n;
        rep(i,1,n-1){
           int u,v; cin>>u>>v;
           adj[u].pb(v);
           adj[v].pb(u);
        }
        cin >> s;
        dfs(1,0);
        cout<<ans+1<<"\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -