제출 #400910

#제출 시각아이디문제언어결과실행 시간메모리
400910Pichon5Bosses (BOI16_bosses)C++17
67 / 100
1575 ms1000 KiB
#include <iostream> #include <bits/stdc++.h> #define pb push_back #define vi vector<int> #define F first #define ll long long #define S second using namespace std; vector<vi>G,G2; int suma[5001]; ll sum=0; void dfs(int nodo, int p){ suma[nodo]=1; for(int i=0;i<G2[nodo].size();i++){ int to=G2[nodo][i]; if(to==p)continue; dfs(to,nodo); suma[nodo]+=suma[to]; } sum+=suma[nodo]; } int main() { int n,x,k; cin>>n; G.resize(n+1); for(int i=1;i<=n;i++){ cin>>k; for(int l=0;l<k;l++){ cin>>x; G[x].pb(i); //cout<<"conecto "<<x<<" "<<i<<endl; } } //cout<<"check "<<G[2].size()<<endl; ll res=1e16; vector<bool>vis; for(int i=1;i<=n;i++){ //cout<<"candidato a maestro "<<i<<endl; G2.assign(n+1,vi()); vis.assign(n+1,false); queue<int>q; int cant=0; q.push(i); vis[i]=1; while(!q.empty()){ int nodo=q.front(); //cout<<"visito "<<nodo<<endl; q.pop(); cant++; for(int l=0;l<G[nodo].size();l++){ int to=G[nodo][l]; //cout<<"hijo "<<to<<endl; if(!vis[to]){ G2[nodo].pb(to); G2[to].pb(nodo); vis[to]=1; q.push(to); } } } if(cant!=n){ continue; } sum=0; dfs(i,-1); //cout<<"pasa "<<sum<<endl; res=min(res,sum); } cout<<res<<endl; return 0; }

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

bosses.cpp: In function 'void dfs(int, int)':
bosses.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<G2[nodo].size();i++){
      |                 ~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for(int l=0;l<G[nodo].size();l++){
      |                         ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...