이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 1000000005
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 100005
vector<int> v[lim];
int dis[lim],n,vis[lim];
inline int bfs(int node){
for (int i=1;i<=n;i++){
dis[i]=OYY;
vis[i]=0;
}
priority_queue <pair<int,int>> pq;
pq.push({1,node});
dis[node]=1;
vis[node]=1;
//cout<<node<<" "<<dis[node]<<endl;
while(!pq.empty()){
int nd=pq.top().second;
pq.pop();
// cout<<pq.top().first<<" "<<pq.top().second<<" "<<dis[nd]<<endl;
for(int i=0;i<v[nd].size();i++){
if(vis[v[nd][i]])continue;
dis[v[nd][i]]=min(dis[v[nd][i]],dis[nd]+1);
vis[v[nd][i]]=1;
pq.push({-dis[v[nd][i]],v[nd][i]});
}
}
int cev=0;
for(int i=1;i<=n;i++){
cev+=dis[i];
}
// cout<<cev<<endl;
return cev;
}
int32_t main(){
faster
cin>>n;
for(int i=1;i<=n;i++){
int deg,tut;cin>>deg;
for(int j=0;j<deg;j++){
cin>>tut;
v[tut].push_back(i);
}
}
int cev=OYY;
for(int i=1;i<=n;i++){
cev=min(cev,bfs(i));
}
cout<<cev<<'\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'long long int bfs(long long int)':
bosses.cpp:28:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<v[nd].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... |