이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* With a little appreciation, in a mostly hollow tone, she says, "Delightful." As if the world has any meaning.
* TASK : Bossa Nova
* AUTHOR : Marszpace
*/
#include<bits/stdc++.h>
using namespace std;
pair<int,int> dfs(vector<vector<int>>& adj, int u){
int res1=0,res2=0;
for(auto v:adj[u]){
auto p=dfs(adj,v);
res1+=p.first;
res2+=p.second;
}
return {res1+res2+1,res2+1};
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin >> n;
vector<vector<int>> adj(n+1,vector<int>());
for(int i=1;i<=n;i++){
int k;
cin >> k;
for(int j=0;j<k;j++){
int v;
cin >> v;
adj[v].push_back(i);
}
}
int res=INT_MAX;
for(int root=1;root<=n;root++){
queue<pair<int,int>> bfs;
bfs.push({root,0});
vector<bool> visited(n+1,false);
int cnt=0;
vector<vector<int>> thisadj(n+1,vector<int>());
while(!bfs.empty()){
auto [u,p]=bfs.front();bfs.pop();
if(visited[u]){continue;}
visited[u]=true;cnt++;
if(p!=0){
thisadj[p].push_back(u);
}
for(auto v:adj[u]){
if(!visited[u]){
bfs.push({v,u});
}
}
}
if(cnt==n){
res=min(res,dfs(thisadj,root).first);
}
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |