이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=5e3+10;
vector <int> g[N];
ll par[N];
bool vis[N];
vector <int> y[N];
void bfs(ll x){
memset(par,0,sizeof par);
queue <int> q;
q.push(x);
memset(vis,0,sizeof vis);
vis[x]=1;
while(q.size()){
ll v=q.front();
q.pop();
for (auto u : g[v]){
if (!vis[u]){
vis[u]=1;
par[u]=v;
y[v].pb(u);
q.push(u);
}
}
}
}
ll dp[N];
ll dfs(ll v,ll p){
for (auto u : y[v]){
if (u==p) continue;
dfs(u,v);
dp[v]+=dp[u];
}
dp[v]+=1;
}
int32_t main(){
ll n;
cin >> n;
for (int i=1;i<=n;i++){
ll k;
cin >> k;
for (int j=0;j<k;j++){
ll x;
cin >> x;
g[x].pb(i);
}
}
ll ans=(ll)1e15;
for (int i=1;i<=n;i++){
for (int j=0;j<N;j++) y[j].clear(),dp[j]=0;
bfs(i);
dfs(i,i);
for (int j=1;j<=n;j++) if (dp[j]==0) dp[i]=(ll)1e15;
ll cnt=0;
for (int j=1;j<=n;j++) cnt+=dp[j];
ans=min(ans,cnt);
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'll dfs(ll, ll)':
bosses.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |