Submission #626430

# Submission time Handle Problem Language Result Execution time Memory
626430 2022-08-11T12:40:42 Z codr0 Power Plant (JOI20_power) C++14
6 / 100
127 ms 468 KB
// Code by Parsa Eslami

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define bit(i,j) ((j>>i)&1)
#define pb push_back
#define lc 2id
#define rc 2id+1
#define dmid int mid=(r+l)/2
#define err(x) cerr<#x<<" : "<<x<<'\n'

using namespace std;
const int N=16+1;
    int get(){
        int x; cin>>x; return x;
    }
vector<int> adj[N];
int sz[N];
bool gen[N];
bool on[N];
int n;

    void dfs(int v,int p){
        sz[v]=on[v];
        for(int u:adj[v]) if(u!=p) dfs(u,v),sz[v]+=sz[u];
    }

    int check(){
        FOR(i,1,n) if(!gen[i]&&on[i]) return 0;
        int rt=0;
        FOR(i,1,n){
            dfs(i,i);
            int y=0;
            for(int u:adj[i]) y+=(sz[u]>0);
            if(on[i]&&y>1) return 0;
            if(gen[i]&&y>1) rt--;
            if(on[i]) rt++;
        }
        return rt;
    }

    int32_t main(){
    iostream::sync_with_stdio(0); cin.tie(0);

    n=get();
    FOR(i,1,n-1){
        int u=get(),v=get();
        adj[u].pb(v);
        adj[v].pb(u);
    }
    string s; cin>>s;
    FOR(i,0,n-1) gen[i+1]=s[i]-'0';
    int ot=0;
    FOR(msk,0,(1<<n)-1){
        FOR(j,0,n-1) on[j+1]=bit(j,msk);
        maxm(ot,check());
    }
    cout<<ot<<'\n';

    return 0;
    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 34 ms 316 KB Output is correct
8 Correct 27 ms 212 KB Output is correct
9 Correct 16 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 46 ms 300 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 9 ms 256 KB Output is correct
14 Correct 4 ms 324 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 127 ms 304 KB Output is correct
18 Correct 65 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 49 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 34 ms 316 KB Output is correct
8 Correct 27 ms 212 KB Output is correct
9 Correct 16 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 46 ms 300 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 9 ms 256 KB Output is correct
14 Correct 4 ms 324 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 127 ms 304 KB Output is correct
18 Correct 65 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 49 ms 300 KB Output is correct
22 Runtime error 1 ms 468 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 34 ms 316 KB Output is correct
8 Correct 27 ms 212 KB Output is correct
9 Correct 16 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 46 ms 300 KB Output is correct
12 Correct 4 ms 212 KB Output is correct
13 Correct 9 ms 256 KB Output is correct
14 Correct 4 ms 324 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 127 ms 304 KB Output is correct
18 Correct 65 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 49 ms 300 KB Output is correct
22 Runtime error 1 ms 468 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -