제출 #813719

#제출 시각아이디문제언어결과실행 시간메모리
813719dijbkrBosses (BOI16_bosses)C++14
0 / 100
5 ms10068 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const int maxn=200005; int n; vector<int>adj[maxn]; vector<int>adj_1[maxn]; int dp[maxn]; bool used[maxn]; bool used_1[maxn]; int DFS(int u) { used[u]=true; for (auto it:adj_1[u]) { if (used[it]==false) { DFS(it); dp[u]+=dp[it]; } } return dp[u]; } int BFS(int u) { memset(used,false,sizeof(used)); memset(used_1,false,sizeof(used_1)); queue<int>q; q.push(u); used_1[u]=true; for (int i=1; i<=n; i++) { adj_1[i].clear(); } while (!q.empty()) { int v=q.front(); q.pop(); for (auto it:adj[v]) { if (used_1[it]==false) { used_1[it]=true; adj_1[v].push_back(it); q.push(it); } } } int res=0; DFS(u); for (int i=1; i<=n; i++) { res+=dp[i]; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i=1; i<=n; i++) { int t; cin >> t; while (t--) { int x; cin >> x; adj[x].push_back(i); } } for (int i=1; i<=n; i++) { dp[i]=1; } // adj_1[1].push_back(2); // adj_1[1].push_back(3); // adj_1[3].push_back(4); // cout << DFS(1); // cout << endl << dp[4]; // cout << BFS(1) << endl; // cout << dp[1]+dp[2]+dp[3]+dp[4] << endl; int ans=INT_MAX; for (int j=1; j<=n; j++) { for (int i=1; i<=n; i++) { dp[i]=1; } //cout << j << " " << BFS(j) << endl; ans=min(ans,BFS(j)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...