이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000000;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,a[li],k,flag,t,dp[li],vis[li];
int cev;
string s;
vector<int> v[li],vv[li];
inline void dfs(int node,int ata){
dp[node]=1;
for(auto go:vv[node]){
if(go==ata)continue;
dfs(go,node);
dp[node]+=dp[go];
}
//~ cout<<node _ dp[node]<<endl;
}
int32_t main(void){
fio();
cin>>n;
FOR{
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
v[x].pb(i);
}
}
cev=1000000000000000000;
FOR{
queue<int> q;
q.push(i);
memset(vis,0,sizeof(vis));
for(int j=1;j<=n;j++)vv[j].clear();
int say=0;
while(q.size()){
say++;
int node=q.front();
q.pop();
vis[node]=1;
for(auto go:v[node]){
if(vis[go])continue;
vv[node].pb(go);
q.push(go);
}
}
if(say!=n){continue;}
int sum=0;
dfs(i,0);
for(int j=1;j<=n;j++)sum+=dp[j];
cev=min(cev,sum);
}
cout<<cev<<endl;
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... |