Submission #350745

#TimeUsernameProblemLanguageResultExecution timeMemory
350745Hossein8320Bosses (BOI16_bosses)C++17
0 / 100
1 ms620 KiB
// That's what she said ! #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int maxn = 5e3 + 9 , modn = 1e9 + 7; int n, v, k, ans = 1e9, cnt[maxn], h[maxn]; bool mark[maxn]; vector <int> adj[maxn], adj2[maxn]; int bfs(int v) { queue <int> q; int H = 0, sum = 0, g = 0; mark[v] = 1; cnt[0] = 1; q.push(v); cout << v << " "; while(q.size()){ v = q.front(); q.pop(); for(auto i : adj[v]){ if(mark[i]) continue; h[i] = h[v] + 1; cnt[h[i]]++; H = max(H , h[i]); mark[i] = 1; cout << i << " "; q.push(i); } } for(int i = H; i > -1; i--){ g += cnt[i]; sum += g; } return sum; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for(int i = 1; i <= n; i++){ cin >> k; for(int j = 0; j < k; j++){ cin >> v; adj[v].push_back(i); adj2[v].push_back(i); adj[i].push_back(v); } } for(int i = 1; i <= n; i++){ swap(adj[i], adj2[i]); int p = bfs(i); cout << p << endl; swap(adj[i], adj2[i]); ans = min(ans , p); for(int i = 0; i <= n; i++) mark[i] = cnt[i] = h[i] = 0; } cout << ans; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int32_t main()':
bosses.cpp:62:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   62 |             mark[i] = cnt[i] = h[i] = 0;
      |                       ~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...