# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735549 | tigar | Bosses (BOI16_bosses) | C++14 | 1 ms | 468 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;
int n;
vector<int>graff[5050], tree[5050];
pair<int, int>d[5050];
bool check[5050], ch[5050];
int val[5050];
vector<pair<int, int> >ord;
int reezz=0;
void bfs(int v, int br)
{
if(check[v])return;
check[v]=true;
if(br!=0)tree[ord[br-1].second].push_back(v);
for(int i=0; i<graff[v].size(); i++)
{
if(!check[graff[v][i]]){ord.push_back({graff[v][i], v}); /*tree[v].push_back(graff[v][i]);*/}
}
if(br==ord.size())return;
bfs(ord[br].first, br+1);
}
int dfs(int v)
{
if(ch[v])return 0;
ch[v]=true;
int ans=1;
for(int i=0; i<tree[v].size(); i++)
{
ans+=dfs(tree[v][i]);
}
reezz+=ans;
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1; i<=n; i++)
{
int k; cin>>k;
d[i].second=i;
for(int j=0; j<k; j++)
{
int a; cin>>a;
graff[a].push_back(i);
d[a].first++;
}
}
sort(d+1, d+n+1);
bfs(d[n].second, 0);
//for(int i=1; i<=n; i++){for(int j=0; j<tree[i].size(); j++)cout<<tree[i][j]<<" "; cout<<endl;}
int k=dfs(d[n].second);
cout<<reezz;
return 0;
}
/*4
1 2
1 1
1 1
1 1
9*/
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... |