Submission #531067

# Submission time Handle Problem Language Result Execution time Memory
531067 2022-02-27T15:00:18 Z Majed Bosses (BOI16_bosses) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define quick ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

using namespace std;

const int N = 5001;

bool vis[N] = {false};

// bool prime[N+1];

vector<int>adj[N];
vector<int>v;
map<int,int>mp;

void bfs(int s) {
  v.clear();
  memset(vis,false,sizeof(vis));
  queue<int>q;
  vis[s] = true;
  q.push(s);
  v.push_back(s);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int child : adj[node]) {
      if (!vis[child]) {
        vis[child] = true;
        q.push(child);
        v.push_back(child);
      }
    }
  }
}

int main() {
    quick;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int u;
        cin >> u;
        adj[u].push_back(i);
        // adj[i].push_back(u);
      }
    }
    ll mn = LLONG_MAX;
    ll sum;
    for (int i = 1; i <= n; i++) {
      int c = 0, sum = 0;
      bfs(i);
      mp.clear();
      if (v.size() != n)
        continue;
      reverse(all(v));
      memset(vis,false,sizeof(vis));
      for (int i = 0; i < v.size(); i++) {
        vis[v[i]] = true;
        for (int child : adj[v[i]]) {
          if (vis[child]) {
            mp[v[i]] += mp[child];
          }
        }
        mp[v[i]]++;
        sum += mp[v[i]];
      }
      mn = min(sum,mn);
    }
    cout << mn << endl;

    // while (!root.empty()) {
    //   queue<int>q;
    //   int level[N];
    //   memset(level,0,sizeof(level));
    //
    //
    //   int u = root.front();
    //   q.push(u);
    //   level[u] = 1;
    //   vis[u] = true;
    //
    //   while (!q.empty()) {
    //     int node = q.front();
    //     q.pop();
    //     for (int child : adj[node]) {
    //       if (!vis[child]) {
    //         vis[child] = true;
    //         q.push(child);
    //         level[child] = level[node] + 1;
    //         mx = max(mx, level[child]);
    //       }
    //     }
    //   }
    //   root.pop();
    // }
    // cout << mx << endl;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:59:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |       if (v.size() != n)
      |           ~~~~~~~~~^~~~
bosses.cpp:63:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |       for (int i = 0; i < v.size(); i++) {
      |                       ~~^~~~~~~~~~
bosses.cpp:73:22: error: no matching function for call to 'min(int&, ll&)'
   73 |       mn = min(sum,mn);
      |                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bosses.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
bosses.cpp:73:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   73 |       mn = min(sum,mn);
      |                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bosses.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
bosses.cpp:73:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   73 |       mn = min(sum,mn);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bosses.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
bosses.cpp:73:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   73 |       mn = min(sum,mn);
      |                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bosses.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
bosses.cpp:73:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   73 |       mn = min(sum,mn);
      |                      ^
bosses.cpp:56:11: warning: unused variable 'c' [-Wunused-variable]
   56 |       int c = 0, sum = 0;
      |           ^
bosses.cpp:54:8: warning: unused variable 'sum' [-Wunused-variable]
   54 |     ll sum;
      |        ^~~