답안 #884294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884294 2023-12-07T06:06:49 Z vjudge1 Bosses (BOI16_bosses) C++17
0 / 100
1 ms 856 KB
/*
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
*/
#include<bits/stdc++.h>
     
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
 
#define pb              push_back
#define F               first
#define S               second
#define len(x)          (int)x.size()
#define all(x)          x.begin(),x.end()
#define file            freopen("txt.in", "r", stdin);freopen("txt.out", "w", stdout);
#define kill(x)         {cout << x << '\n'; return 0;}
//#define int             long long

const int N = 5e3 + 1e3 + 5, LG = 21, MOD = 1e9+7;// 998244353
const ll inf =  4557430888798830399;

int n, dp[N], ans;
pii deg[N];
vector<int> g[N], G[N];
bitset<N> mark;
queue<int> q;

void dfs(int v) {
    mark[v] = 1;
    dp[v] = 1;
    for(int u : G[v]) {
        if(!mark[u]) {
            dfs(u);
            dp[v] += dp[u];
        }
    }
    ans += dp[v];

}

signed main() { 
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n;

    for(int i = 1; i <= n; ++i) {
        
        deg[i].S = i;
        int sz;
        cin >> sz;
        for(int j = 0; j < sz; ++j) {
            int v;
            cin >> v;
            g[v].pb(i);
            ++deg[v].F;
        }
    }


    sort(deg+1, deg+n+1);
    reverse(deg+1, deg+1+n);
    int x = deg[1].S;
    


    q.push(x);
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        mark[v] = 1;
        for(int u : g[v]) {
            if(!mark[u]){
                mark[u] = 1;
                q.push(u);
                G[v].pb(u);
            }
        }
    }
    mark.reset();


    dfs(deg[1].S);

    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Incorrect 0 ms 856 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Incorrect 0 ms 856 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Incorrect 0 ms 856 KB Output isn't correct
5 Halted 0 ms 0 KB -