This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma optimization_level 3
// Defines
#define pb push_back // kak push_back 5
#define endl '\n'
#define FOR(i,start,end) for(int i = start;i < end;i ++)
#define REV(i,start,end) for(int i = start;i >= end;i --)
#define precal(x) fixed << setprecision(x)
#define F first
#define S second
#define sz(x) (ll)x.size()
#define all(x) (x).begin(),(x).end()
#define m_p make_pair
#define mt make_tuple
#define str to_string
// #ifndef ONLINE_JUDGE
// #define cerr if(false) cerr
// #endif
const ll mxn = 1e4;
// const ll k = 1000;
// const ll org = 10000;
const ll inf = 1e9 + 7;
// const ll mod = 998244353;
vector <ll> v[mxn];
ll n,k = 0;
ll cnt[mxn],t[mxn];
void dfs(ll x,ll p = 1){
if(t[x] == 0){
t[x] = p;
cnt[p] ++,k ++;
}
else{
cnt[t[x]] --,t[x] = p,cnt[p] ++;
}
for(auto i : v[x]){
if(t[i] == 0 || p + 1 < t[i]) dfs(i,p + 1);
}
}
int main(){
// freopen("sparse.in","r",stdin);
// freopen("sparse.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll tt = 1;
// cin >> tt;
while(tt --){
cin >> n;
FOR(i,1,n + 1){
ll t;
cin >> t;
while(t --){
ll x;
cin >> x;
v[i].pb(x);
}
}
ll ans = inf;
FOR(i,1,n + 1){
k = 0;
memset(cnt,0,sizeof(cnt));
memset(t,0,sizeof(t));
dfs(i);
if(k != n) continue;
ll sum = 0;
for(int j = 1;j <= n;j ++){
sum += cnt[j] * j;
}
ans = min(ans,sum);
// cout << i << " " << ans << endl;
}
cout << ans;
}
}
Compilation message (stderr)
bosses.cpp:9: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
9 | #pragma GCC optimization ("O3")
|
bosses.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
10 | #pragma GCC optimization ("unroll-loops")
|
bosses.cpp:11: warning: ignoring '#pragma optimization_level ' [-Wunknown-pragmas]
11 | #pragma optimization_level 3
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |