Submission #1108279

#TimeUsernameProblemLanguageResultExecution timeMemory
1108279cuctuyetazBosses (BOI16_bosses)C++14
100 / 100
403 ms14224 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define endl '\n' #define all(v) v.begin(), v.end() #define GBIT(mask, i) (((mask) >> (i)) & 1) #define BIT(i) (1ll << (i)) #define pb push_back #define fu(i, l, r) for (int i = (int) (l); i <= (int)(r); i++) #define fd(i, r, l) for (int i = (int) (r); i >= (int)(l); i--) typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef unsigned long long ull; typedef double dl; const int MAXN =5e5 + 55; const ll MOD = 1e9 + 7; const ll oo = 1ll * MOD * MOD; int n; vector <int> ke[MAXN]; void rf() { cin >> n; fu(i, 1, n) { int k, u; cin >> k; while (k--) { cin >> u; ke[u].pb(i); } } } int dist[MAXN]; void solve() { ll res = oo; fu(i, 1, n) { queue <int> p; int cursize = 0; fu(j, 1, n) dist[j] = 0; dist[i] = 1; p.push(i); ll ans = 0; while (p.size()) { int u = p.front(); cursize++; ans += dist[u]; p.pop(); for (int v : ke[u]) if (dist[v] == 0) { dist[v] = dist[u] + 1; p.push(v); } } if (cursize == n) res = min(res, ans); } cout << res << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "xD" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; // cin >> ntest; fu(i, 1, ntest) { rf(); solve(); } cerr << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " ms \n"; return 0; }

Compilation message (stderr)

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