# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936258 | wateronenn | Bosses (BOI16_bosses) | C++14 | 1 ms | 2652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+9;
vector<int> g[N];
bool visit[N]={0};
int dfs(int u){
visit[u] = true;
int nub = 1;
for(auto v : g[u]){
if(!visit[v]){
nub+=dfs(v);
}
}
return nub;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
int n,m;
cin>>n;
for(int i=1;i<=n;i++){
int k;
cin>>k;
for(int j=1;j<=k;j++){
cin>>m;
g[i].push_back(m);
}
}
int sum = 0;
for(int i=1;i<=n;i++){
if(!visit[i]) {
int res = dfs(i);
// cout<<res<<" ";
sum += 1<<res-1;
}
}
cout<<sum;
return 0;
}
/*
4
1 4
3 1 3 4
2 1 2
1 3
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |