이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<set>
#include<map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,f,g=1,h[N],arr[N];
string s;
vector<lo>v[N];
lo bfs(lo x){
for(lo i=1;i<=a;i++)h[i]=0;
queue<pair<lo,lo> >q;
q.push({x,1});
while(q.size()){
if(h[q.front().st]){q.pop(); continue;}
h[q.front().st]=q.front().nd;
for(lo i=0;i<v[q.front().st].size();i++){
if(h[v[q.front().st][i]]==0)q.push({v[q.front().st][i],q.front().nd+1});
}
q.pop();
}
lo sum=0;
for(lo i=1;i<=a;i++){
if(h[i]==0) return mod;
sum+=h[i];
}
return sum;
}
void solve(){
cin >> a;
for(lo i=1;i<=a;i++){
lo x,y;
cin >> x;
for(lo j=1;j<=x;j++){
cin >> y;
v[y].pb(x);
}
}
lo mn=mod;
for(lo i=1;i<=a;i++){
for(lo j=1;j<=a;j++)h[j]=0;
mn=min(mn,bfs(i));
}
cout << mn << endl;
}
int main(){
#ifdef local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// cin >> g;
while(g--)solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'lo bfs(lo)':
bosses.cpp:32:15: warning: comparison of integer expressions of different signedness: 'lo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(lo i=0;i<v[q.front().st].size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |