이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k;
const int mx=1000000;
const int MOD=1000000007;
//fast exponentiation
int visited[100000];
vector<int>edges[mx];
ll co=0;
ll bfs(int s){
queue<pair<int,int>>q;
q.push({1,s});
ll sum=0;
while(!q.empty()){
pair<int,int>me=q.front();
q.pop();
int node=me.second;
sum+=me.first;
co++;
visited[node]=1;
for(int i=0;i<edges[node].size();i++){
if(!visited[edges[node][i]]){
q.push({me.first+1,edges[node][i]});
visited[edges[node][i]]=1;
}
}
}if(co==n){return sum;}else{return 1e9;}
}
int main() {
/*freopen("poetry.in" , "r" , stdin) ;
freopen("poetry.out" , "w" , stdout) ;
*/
cin>>n;
for(int i=1;i<=n;i++){
int k;cin>>k;
for(int j=0;j<k;j++){
ll y;
cin>>y;
edges[y].push_back(i);
}
}
ll ans=1e9;
for(int i=1;i<=n;i++){
memset(visited,0,sizeof(visited));
co=0;
ll an=bfs(i);
if(co==n){ans=min(ans,an);}
// cout<<co<<endl;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'll bfs(int)':
bosses.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<edges[node].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... |