Submission #79545

#TimeUsernameProblemLanguageResultExecution timeMemory
79545MoesashiMinamotoBosses (BOI16_bosses)C++14
67 / 100
1537 ms1276 KiB
#include <bits/stdc++.h> using namespace std; int n; vector< int > acc[5003]; int m; int vis[5003]; int pa[5003]; vector<int> g[5003]; int sal[5003]; long long res = LLONG_MAX; long long dfs(int u, int root) { vis[u] = 0; if (u == root) { for (int i = 1; i <= n; i++) { sal[i] = 1ll*n*(n-1)/2; } } long long cres = 1; for (auto v : g[u]) { cres += dfs(v, root); } sal[u] = cres; if (u != root) return cres; else { cres = 0; for (int i = 1; i <= n; i++) { cres += sal[i]; if (cres >= res) { return LLONG_MAX; } } return cres; } } long long fouck(int pos) { queue<int> q; q.push(pos); vis[pos] = 1; for (int i = 1; i <= n; i++) { g[i].clear(); } while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : acc[u]) { if (!vis[v]) { q.push(v); g[u].push_back(v); vis[v] = 1; } } } return dfs(pos, pos); } signed main() { int x, y; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &m); for (int j = 1; j <= m; j ++) { scanf("%d", &x); acc[x].push_back(i); } } for (int i = 1; i <= n; i++) { res = min(res, fouck(i)); } cout << res; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:61:9: warning: unused variable 'y' [-Wunused-variable]
  int x, y;
         ^
bosses.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bosses.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &m);
   ~~~~~^~~~~~~~~~
bosses.cpp:66:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &x);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...