제출 #125135

#제출 시각아이디문제언어결과실행 시간메모리
125135miguelBosses (BOI16_bosses)C++14
100 / 100
1018 ms916 KiB
#include <bits/stdc++.h> using namespace std; #define rc(x) return cout<<x<<endl,0 #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define sz size() #define x first #define y second #define pi pair <int, int> #define pii pair <pi, int> #define vi vector <int> const ll mod = 1e9 + 7; int n, q; vector<int> g[10002]; int u[10001], d[10001]; int tst(int x){ queue <int> q; for(int i=1; i<=n; i++)u[i]=0, d[i]=0; q.push(x); u[x]=1, d[x]=1; while(!q.empty()){ int p=q.front(); q.pop(); for(int j=0; j<g[p].size(); j++){ int i=g[p][j]; if(u[i]==0){ u[i]=1; d[i]=d[p]+1; q.push(i); } } } int ans=0; for(int i=1; i<=n; i++){ if(u[i]==0) return -1; else ans+=d[i]; } return ans; } int main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cin>>n; for(int i=1; i<=n; i++){ int k; cin>>k; for(int j=1; j<=k; j++){ int x; cin>>x; g[x].pb(i); } } int ans=1e9; for(int i=1; i<=n; i++){ int cur=tst(i); //cout<<i<<" "<<cur<<endl; if(cur!=-1) ans=min(cur, ans); } if(ans!=1e9)cout<<ans<<endl; else cout<<-1<<endl; }

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

bosses.cpp: In function 'int tst(int)':
bosses.cpp:26:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<g[p].size(); j++){
                ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...