제출 #767611

#제출 시각아이디문제언어결과실행 시간메모리
7676111neBosses (BOI16_bosses)C++14
67 / 100
1586 ms1908 KiB
/* * author : Apiram * created: 27.06.2023 03:25:28 */ #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<set<int>>adj(n); vector<vector<int>>rev_adj(n); for (int i = 0;i<n;++i){ int k;cin>>k; for (int j = 0;j<k;++j){ int x;cin>>x; --x; if (i == x)continue; adj[x].insert(i); rev_adj[i].push_back(x); } } int pos = 1e9; for (int i = 0;i<n;++i){ queue<int>q; vector<set<int>>bdj = adj; int curv = 1; int ans = 0; vector<int>visited(n,false); vector<int>depth(n,0); visited[i] = true; vector<vector<int>>nx(n); function<pair<int,int>(int)>dfs = [&](int u){ pair<int,int> v = {1,0}; for (auto x:nx[u]){ auto vv = dfs(x); v.first+=vv.first; v.second+=vv.second; } v.second+=v.first; return v; }; q.push(i); vector<int>cost(n,1); while(!q.empty()){ auto u = q.front(); q.pop(); for (auto x:bdj[u]){ if (!visited[x]){ visited[x] = true; depth[x] = depth[u] + 1; nx[u].push_back(x); q.push(x); curv++; for (auto y:rev_adj[x]){ if (y == u)continue; if (bdj[y].find(x)!=bdj[y].end()) bdj[y].erase(x); } } } } if (curv == n){ //cout<<'\n'; pos = min(pos,dfs(i).second); } } cout<<pos<<'\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'int main()':
bosses.cpp:30:7: warning: unused variable 'ans' [-Wunused-variable]
   30 |   int ans = 0;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...