# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
838888 |
2023-08-28T05:28:09 Z |
vjudge1 |
Bosses (BOI16_bosses) |
C++17 |
|
1 ms |
340 KB |
/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,k,cnt;
vector<ll>v[2001];
vector<ll>g[2001];
bool used[2001];
ll ans[2001];
bool was[2001];
void dfs(ll x)
{
//cout<<x<<":";
ans[x]=1;
was[x]=1;
for(int it:g[x])
{
if(!was[it])
{
dfs(it);
ans[x]+=ans[it];
}
}
}
void anomalous_solve()
{
cin>>n;
ll x;
for(int i=1;i<=n;i++)
{
cin>>k;
for(int j=1;j<=k;j++)
{
cin>>x;
v[x].push_back(i);
}
}
ll mx=0,pos=-1;
for(int i=1;i<=n;i++)
{
//cout<<i<<":"<<v[i].size()<<"\n";
if(v[i].size()>mx)
{
mx=v[i].size();pos=i;
}
}
queue<ll>q;
q.push(pos);
while(q.size()>0)
{
ll x=q.front();
for(int it:v[x])
{
if(!used[it])
{
g[x].push_back(it);
q.push(it);
used[it]=1;
}
}
q.pop();
}
dfs(pos);
for(int i=1;i<=n;i++)
{
cnt+=ans[i];
//cout<<ans[i]<<" ";
}
cout<<cnt;
}
int main()
{
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
Compilation message
bosses.cpp: In function 'void anomalous_solve()':
bosses.cpp:44:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
44 | if(v[i].size()>mx)
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |