Submission #695144

#TimeUsernameProblemLanguageResultExecution timeMemory
695144Mr_PhBosses (BOI16_bosses)C++14
0 / 100
0 ms212 KiB
///Never gonna give you up. #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; typedef long long int lli; typedef unsigned long long ull; using namespace std; using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; const ll mod=(ll)1e9+7; const ll mod1=998244353; ///the defines :) #define endl '\n' #define vi vector<int> #define vll vector<ll> #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i]; #define all(arr) arr.begin(),arr.end() #define allr(arr) arr.rbegin(),arr.rend() #define sz size() #define int long long ///the end of the defines ;) void bla() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("notsus.txt","w",stdout); #endif } int n; vector<vector<int>>padj; vector<vector<int>>adj; vector<bool>vs; map<int,int>val; vector<bool>vs1; map<int,int>val1; vector<vector<int>>build(int node) { vector<vector<int>>yay(n+1); map<int,int>mp; queue<int>q; q.push(node); map<int,int>mp1; while(q.sz) { mp1[q.front()]++; mp[q.front()]++; //cout<<q.front()<<" ez"<<endl; for(auto i:padj[q.front()]) { if(!mp[i]) { //cout<<i<<" "; yay[q.front()].push_back(i); mp[i]++; } if(!mp1[i]){ q.push(i); mp1[i]++; //cout<<i<<endl; } } //cout<<endl; q.pop(); } return yay; } int hello=0; void dfs(int node) { vs[node]=true; //cout<<endl; //cout<<node<<" node"<<endl; val[node]=1; //cout<<adj[node].sz<<" "<<node<<endl; for(auto i:adj[node]) { if(!vs[i])dfs(i); val[node]+=val[i]; //cout<<i<<" "; } } void preprocess(){} void solve() { cin>>n; padj.resize(n+1); vs.resize(n+1); vs1.resize(n+1); adj.resize(n+1); for(int i=0;i<n;i++) { int x; cin>>x; for(int j=0;j<x;j++) { int a; cin>>a; padj[a].push_back(i+1); } } int ans=1e9; for(int i=1;i<=n;i++) { vs=vs1; val=val1; adj=build(i); hello=0; /* for(int j=1;j<=n;j++) { cout<<j<<endl; for(auto x:adj[j]) { cout<<x<<" "; } cout<<endl; } cout<<"xxxxxxxxxxxxxxx"<<endl; */ dfs(i); for(auto i:val) { //cout<<i.first<<" "<<i.second<<endl; hello+=i.second; } //cout<<hello<<endl; //cout<<"--------"<<endl; ans=min(ans,hello); } cout<<ans<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); preprocess(); //bla(); int t=1; //cin>>t; while(t--) solve(); }

Compilation message (stderr)

bosses.cpp: In function 'void bla()':
bosses.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("notsus.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...