제출 #1261338

#제출 시각아이디문제언어결과실행 시간메모리
1261338goulthenBosses (BOI16_bosses)C++20
0 / 100
1 ms2628 KiB
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, b, a) for (int i = b; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define lsb(x) (x)&(-x)
#define bug(x) cerr << #x << " " << x << endl;
 
void setIO(string name = "") {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    if (!name.empty()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
 
ll fexp(ll a, ll b, ll m) {
    if (b == 0) return 1LL;
    ll p = a;
    ll ans = 1;
    while (b > 0) {
        if (b % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        b >>= 1;
    }
    return ans;
}
 
const int MAXN = 1e5 + 10;
const int INF = 1e18 + 5;
const int MOD = 1e9 + 7;
vector<int> g[MAXN];

void solve() {
    int n;cin >> n;
    rep(i,1,n) {
        int k;cin >>k;
        while (k--) {
            int x;cin >> x;
            g[x].pb(i);
        }
    }

    int ans = INF;
    rep(i,1,n) {
        vector<bool> mk(n+1);

        queue<pii> q;
        q.push({i,0});

        int cur = 0, t = 0;
        while (!q.empty()) {
            auto [u,d] = q.front();
            q.pop();
            cur+=d;
            if (mk[u]) continue;
            mk[u] = 1;

            for (int &v : g[u]) {
                if (mk[v]) continue;
                q.push({v,d+1});
            }
        }

        rep(i,1,n) t += mk[i];
        if (t == n) ans = min(ans, cur);
    }

    cout << ans + n << '\n';
}

int32_t main() {
    setIO();
    int tt = 1;
    //cin >> tt;
 
    while (tt-- > 0) solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'void setIO(std::string)':
bosses.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...