Submission #946218

#TimeUsernameProblemLanguageResultExecution timeMemory
946218veljkoBosses (BOI16_bosses)C++17
0 / 100
1527 ms240080 KiB
/*****from dust I have come, dust I will be*****/ #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define forn(i,n) for(int i=0;i<n;i++) int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;} const int MOD = 1000000007; //const int MOD = 998244353; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key /* int k = A.order_of_key(p[i].second); A.erase(A.find_by_order(k)); erase element from pbds multiset */ int bfs(vector<vector<int>>&g, int start, int n){ vector<int>vis(n, 0); queue<int>q; q.push(start); vis[start] = 1; int cost = 0, cnt = 0; while (!q.empty()){ auto t = q.front(); q.pop(); for (auto x : g[t]){ if (vis[x] == 0){ cnt++; vis[x] = vis[t] + 1; cost += vis[x]; q.push(x); } } } if (cnt != n-1) return 1e18; return cost + 1; } void solve(){ int n; cin >> n; vector<vector<int>>g(n); forn(i,n){ int sz; cin >> sz; int x; forn(j,sz){ cin >> x; g[x-1].push_back(i); } } int ans = 1e18; forn(i,n){ ans = min(ans, bfs(g,i,n)); } cout <<ans<<'\n'; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin >>t; for (int i=1;i<=t;i++){ solve(); } return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int32_t 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("input.txt", "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("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...