제출 #1167192

#제출 시각아이디문제언어결과실행 시간메모리
1167192sasdeBosses (BOI16_bosses)C++20
100 / 100
468 ms784 KiB
#include<bits/stdc++.h>
#define task "strdel"
#define int long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
using namespace std;
const int N=5e3+5,lg=20,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
int n,ans=1e18,num;
vector<int>a[N];
int h[N],dist[N];

void bfs(int u){
    for(int i=1;i<=n;++i)h[i]=-1;
    h[u]=1;
queue<int>p;
p.em(u);
int sz=n;
while(!p.empty()){
    int x=p.front();
    p.pop();
    for(int v:a[x]){
        if(h[v]==-1){
            h[v]=h[x]+1;
            p.em(v);
            --sz;
            // cout <<x<<" "<<v.fi<<" "<<v.se<<'\n';
        }
    }
}
if(sz!=1)return;
int res=0;
for(int i=1;i<=n;++i){
    res+=h[i];

}
// cout <<u<<" "<<h[u]<<'\n';
ans=min(ans,res);
}
void solve(){
    cin >> n ;
    for(int i=1;i<=n;++i){
        int k;
        cin >> k;
        for(int j=1;j<=k;++j){
            int u;
            cin >> u;
            // cout <<i<<" "<<num<<'\n';
            a[u].emb(i);
        }
    }
    for(int i=1;i<=n;++i){
        bfs(i);
    }
    cout << ans;

}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
    cout<<'\n';
}

}

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main()
      | ^~~~
bosses.cpp: In function 'int main()':
bosses.cpp:81:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:82:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...