이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< int,int > 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];
vector<PII> ok;
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{
ok.pb(mp(v[i].size(),i));
}
sort(ok.begin(),ok.end());
reverse(ok.begin(),ok.end());
int kok=sqrt(ok.size()-1);
kok=kok*35;
kok=min(kok,(int)ok.size());
for(int jj=0;jj<kok;jj++){
int i=ok[jj].se;
//~ memset(sub,-1,sizeof(sub));
for(int j=1;j<=n;j++){
vv[j].clear();
vis[j]=0;
}
bfs(i);
dfs(i,0,i);
flag=0;
cev=0;
for(int j=1;j<=n;j++){
if(vis[j]==0){flag=1;break;}
cev+=sub[j];
//~ if(i==1)cout<<sub[j]<<" ";
}
//~ cout<<cev<<endl;
if(!flag)mn=min(mn,cev);
}
//~ sort(ok.begin(),ok.end());
//~ kok=min(kok,ok.size());
//~ for(int jj=0;jj<kok;jj++){
//~ int i=ok[jj].se;
//memset(sub,-1,sizeof(sub));
//~ for(int j=1;j<=n;j++){
//~ vv[j].clear();
//~ vis[j]=0;
//~ }
//~ bfs(i);
//~ dfs(i,0,i);
//~ flag=0;
//~ cev=0;
//~ for(int j=1;j<=n;j++){
//~ if(vis[j]==0){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;
}
컴파일 시 표준 에러 (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... |