답안 #872835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872835 2023-11-13T23:03:37 Z shezitt Power Plant (JOI20_power) C++17
6 / 100
1500 ms 7000 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define gcd(a, b) __gcd(a, b)
#define lcm(a,b) a*b/gcd(a,b)
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define fst first
#define snd second
#define sz(x) (int)x.size()
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fore(a, b, c) for(int a=b; a<c; ++a)
#define all(x) x.begin(), x.end()
#define endl '\n';

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define raya cerr << "==========================" << endl;
#define int ll

const double EPS = 1e-7;
const double PI = acos(-1);
const int MOD = 1e9+7;  
int TC = 1;

const int N = 2e5+5;
vi adj[N];
int pa[N], n;
vi gen;
bool on[N];
bool isGen[N];
string s;

void dfs(int i, int pre=-1){
    pa[i] = pre;
    for(auto u : adj[i]){
        if(u == pre) continue;
        dfs(u, i);
    }
}

bool dfsCount(int i, int pre=-1){
    if(on[i]) return 1;
    for(auto u : adj[i]){
        if(u == pre) continue;
        if(dfsCount(u, i)) return 1;
    }
    return 0;
}

void solve(){
    cin >> n;
    fore(i, 1, n){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    cin >> s;
    fore(i, 0, n){
        if(s[i] == '1'){
            gen.pb(i+1);
            isGen[i+1] = 1;
        }
    }
    dfs(1);
    int ans = 0;
    for(int mask=0; mask<(1<<sz(gen)); ++mask){
        fore(i, 1, n+1){
            on[i] = 0;
        }
        fore(i, 0, sz(gen)){
            if((mask >> i) & 1){
                on[gen[i]] = 1;
            }
        }
        int cur = __builtin_popcountll(mask);
        // check
        fore(i, 1, n+1){
            if(!isGen[i]) continue;
            int tmp = 0;
            for(auto u : adj[i]){
                tmp += dfsCount(u, i);
            }
            if(tmp > 1){
                cur--;
                cur -= on[i];
            }
        }
        ans = max(ans, cur);
    }
    cout << ans;
}

signed main(){
    fast;
    // cin >> TC;
    while(TC--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6932 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 17 ms 6748 KB Output is correct
8 Correct 20 ms 6936 KB Output is correct
9 Correct 9 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 18 ms 6744 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 14 ms 6932 KB Output is correct
18 Correct 7 ms 6940 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 16 ms 6940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6932 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 17 ms 6748 KB Output is correct
8 Correct 20 ms 6936 KB Output is correct
9 Correct 9 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 18 ms 6744 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 14 ms 6932 KB Output is correct
18 Correct 7 ms 6940 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 16 ms 6940 KB Output is correct
22 Execution timed out 1596 ms 7000 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6932 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 17 ms 6748 KB Output is correct
8 Correct 20 ms 6936 KB Output is correct
9 Correct 9 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 18 ms 6744 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 14 ms 6932 KB Output is correct
18 Correct 7 ms 6940 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 16 ms 6940 KB Output is correct
22 Execution timed out 1596 ms 7000 KB Time limit exceeded
23 Halted 0 ms 0 KB -