이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 5050;
const ll inf = 1e9;
ll dist[mxn];
queue<int> q;
vector<int> paths[mxn];
int N,M;
ll BFS(int s){
q.push(s);
fill(dist,dist+N+1,inf);
dist[s] = 1;
q.push(s);
while(!q.empty()){
auto now = q.front();
q.pop();
for(auto nxt:paths[now]){
if(dist[nxt]>dist[now]+1){
dist[nxt] = dist[now]+1;
q.push(nxt);
}
}
}
return accumulate(dist+1,dist+N+1,0ll);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++){
int k;
cin>>k;
while(k--){
int tmp;
cin>>tmp;
paths[tmp].push_back(i);
}
}
ll ans = inf*inf;
for(int i = 1;i<=N;i++)ans = min(ans,BFS(i));
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |