Submission #1279187

#TimeUsernameProblemLanguageResultExecution timeMemory
1279187zagaroBosses (BOI16_bosses)C++20
0 / 100
1 ms572 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> /**zagaro & lauren <3**/ #define mod 1000000007 //1e9 + 7 #define pi acos(-1) #define wl while #define str string #define ENDL "\n" #define sal ' ' #define tp_set ll #define prc(n) cout.precision(n);cout<<fixed; #define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef bool bl; typedef char car; using namespace std; using namespace __gnu_pbds; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, a, x, r=LONG_LONG_MAX, s, nod, val; cin>>n; vector<vector<ll> > adj(n+1); for(int i=1;i<=n;i++){ cin>>a; wl(a--){ cin>>x; adj[x].push_back(i); } } for(int i=1;i<=n;i++){ queue<tuple<ll,ll> > pq; vector<bl> vis(n+1, false); vis[i] = true; pq.push({i, 1}); s=0; wl(!pq.empty()){ tie(nod, val) = pq.front(); pq.pop(); s += val; for(int j=0;j<adj[nod].size();j++){ if(!vis[adj[nod][j]]){ pq.push({adj[nod][j], val+1}); vis[adj[nod][j]] = true; } } } r=min(r, s); } cout<<r<<ENDL; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...