Submission #292224

#TimeUsernameProblemLanguageResultExecution timeMemory
292224AbdelrahmanBosses (BOI16_bosses)C++17
67 / 100
1519 ms1260 KiB
#include <bits/stdc++.h> #define endl '\n' #define modulo 1000000007 #define int long long #pragma GCC optimize("-Ofast") #define float double #define PI 3.141592653589793238462643383279502884 #define sinDegrees(x) sin((x) * PI / 180.0) #define tanDegrees(x) tan((x) * PI / 180.0) #define atanDegrees(x) atan(x)* 180.0 / PI using namespace std; unordered_map<int, vector<int> > mp; bool visited[5001] = {0}; int finale = 0, done=0; void solve(int emp) { vector<pair<int, int> > v; visited[emp]=1; v.push_back({emp, 1}); done++; finale++; int x=0; while (x!=v.size()) { auto p = v[x]; for (int i=0;i<mp[p.first].size();i++) { int a = mp[p.first][i]; //cout<<a<<" "; if (visited[a]) continue; done++; visited[a]=1; v.push_back({a, p.second+1}); finale+=p.second+1; } x++; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for (int i=0;i<n;i++) { int a; cin>>a; while (a--) { int b; cin>>b; mp[b-1].push_back(i); } } int mini=INT_MAX; for (int i=0;i<n;i++) { solve(i); if (done==n) { mini = min(finale, mini); } for (int j=0;j<n;j++) { visited[j]=0; } finale = 0; done=0; } cout<<mini; }

Compilation message (stderr)

bosses.cpp: In function 'void solve(long long int)':
bosses.cpp:26:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     while (x!=v.size())
      |            ~^~~~~~~~~~
bosses.cpp:29:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i=0;i<mp[p.first].size();i++)
      |                      ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...