This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 5002;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,sub[li],mn=inf,vis[li];
int cev;
string s;
vector<int> v[li],vv[li];
inline void bfs(int ind){
queue<int> q;
while(q.size())q.pop();
q.push(ind);
while(q.size()){
int node=q.front();
q.pop();
//~ if(vis[node])continue;
vis[node]=1;
for(int i=0;i<(int)v[node].size();i++){
if(vis[v[node][i]])continue;
vis[v[node][i]]=1;
q.push(v[node][i]);
//~ cout<<node<<" ; ; "<<v[node][i]<<endl;
vv[node].pb(v[node][i]);
}
}
}
inline void dfs(int node,int ata,int yaz){
sub[node]=1;
for(int i=0;i<(int)vv[node].size();i++){
int go=vv[node][i];
if(go==ata)continue;
//~ cout<<node<<" : ; "<<go<<" : ;"<<yaz<<endl;
dfs(go,node,yaz);
sub[node]+=sub[go];
}
}
int main(void){
scanf("%d",&n);
FOR{
scanf("%d",&k);
for(int j=1;j<=k;j++){
int x;
scanf("%d",&x);
v[x].pb(i);
}
}
FOR{
memset(sub,-1,sizeof(sub));
memset(vis,0,sizeof(vis));
for(int j=1;j<=n;j++)vv[j].clear();
bfs(i);
dfs(i,0,i);
flag=0;
cev=0;
for(int j=1;j<=n;j++){
if(sub[j]==-1){flag=1;break;}
cev+=sub[j];
//~ if(i==1)cout<<sub[j]<<" ";
}
//~ cout<<cev<<endl;
if(!flag)mn=min(mn,cev);
}
printf("%d\n",mn);
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
bosses.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&k);
~~~~~^~~~~~~~~
bosses.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x);
~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |