제출 #1255246

#제출 시각아이디문제언어결과실행 시간메모리
1255246hoa208Bosses (BOI16_bosses)C++20
100 / 100
368 ms796 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
const int N = 5003;
int h[N], a[N];
ll dp[N];
vector<int> g[N];
int n;
ll bfs(int s) {
    queue<int> q;
    FOR(i, 1, n) h[i] = 0, dp[i] = 0;
    q.push(s);
    h[s] = -1;
    int m = 0;
    while(!q.empty()) {
        ll u = q.front();
        q.pop();
        a[++m] = u;
        for(auto v : g[u]) {
            if(h[v] != 0) continue;
            h[v] = u;
            q.push(v);
        }
    }
    if(m != n) return INF;
    ll ans = 0;
    FORD(i, m, 1) {
        int v = a[i];
        dp[v]++;
        ans += dp[v];
        dp[h[v]] += dp[v];
    }
    return ans;
}
void hbmt() {
    cin >> n;
    FOR(i, 1, n) {
        int m;
        cin >> m;
        while(m--) {
            int x;
            cin >> x;
            g[x].push_back(i);
        }
    }
    ll ans = INF;
    FOR(i, 1, n) {
        ans = min(ans, bfs(i));
    }
    cout << ans;
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

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

bosses.cpp: In function 'int main()':
bosses.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...