Submission #802973

#TimeUsernameProblemLanguageResultExecution timeMemory
802973SamAndKeys (IOI21_keys)C++17
0 / 100
7 ms14420 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define m_p make_pair #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() const int N = 300005; int n; vector<pair<int, int> > g[N]; int c[N]; bool cc[N]; vector<int> v[N]; int stup(int x, const vector<int>& r) { int ans = 0; queue<int> q; q.push(x); queue<int> qq; while (!q.empty()) { int x = q.front(); q.pop(); if (c[x]) continue; ++ans; qq.push(x); qq.push(r[x]); c[x] = true; cc[r[x]] = true; while (!v[r[x]].empty()) { q.push(v[r[x]].back()); v[r[x]].pop_back(); } for (int i = 0; i < sz(g[x]); ++i) { int h = g[x][i].fi; if (cc[g[x][i].se]) q.push(h); else { qq.push(g[x][i].se); v[g[x][i].se].push_back(h); } } } while (!qq.empty()) { int x = qq.front(); qq.pop(); c[x] = false; cc[x] = false; v[x].clear(); } return ans; } int u[N]; vector<vector<int> > vv; bool dfs(int x) { c[x] = 1; if (!c[u[x]]) { if (dfs(u[x])) { c[x] = 2; return true; } } if (c[u[x]] == 1) { vector<int> v; int y = u[x]; while (y != x) { v.push_back(y); y = u[y]; } v.push_back(x); vv.push_back(v); c[x] = 2; return true; } c[x] = 2; return false; } std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { n = sz(r); int m = sz(u); std::vector<int> ans(n, 0); for (int i = 0; i < m; ++i) { if (u[i] == v[i]) continue; g[u[i]].push_back(m_p(v[i], c[i])); g[v[i]].push_back(m_p(u[i], c[i])); } bool ff = false; for (int x = 0; x < n; ++x) { bool f = false; for (int i = 0; i < g[x].size(); ++i) { if (g[x][i].se == r[x]) { ::u[x] = g[x][i].fi; f = true; break; } } if (!f) { ff = true; break; } } if (ff) { for (int x = 0; x < n; ++x) { bool f = false; for (int i = 0; i < g[x].size(); ++i) { if (g[x][i].se == r[x]) { f = true; break; } } if (!f) ans[x] = 1; } return ans; } for (int x = 0; x < n; ++x) { if (!c[x]) { dfs(x); } } for (int x = 0; x < n; ++x) c[x] = false; vector<int> s; for (int i = 0; i < sz(vv); ++i) { s.push_back(stup(vv[i][0], r)); } int minu = s[0]; for (int i = 0; i < sz(vv); ++i) minu = min(minu, s[i]); for (int i = 0; i < sz(vv); ++i) { if (s[i] == minu) { for (int j = 0; j < sz(vv[i]); ++j) ans[vv[i][j]] = 1; } } return ans; }

Compilation message (stderr)

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for (int i = 0; i < g[x].size(); ++i)
      |                         ~~^~~~~~~~~~~~~
keys.cpp:130:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |             for (int i = 0; i < g[x].size(); ++i)
      |                             ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...