Submission #531125

#TimeUsernameProblemLanguageResultExecution timeMemory
5311254fectaBitaro’s Party (JOI18_bitaro)C++17
0 / 100
10 ms19208 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ld long double #define pii pair<int, int> #define f first #define s second #define boost() cin.tie(0), cin.sync_with_stdio(0) const int MN = 200005; int n, m, q, u, v, k, dp[MN], ans[MN], par[MN]; vector<int> a[MN], r[MN], nodes[MN]; vector<vector<int>> qs[MN]; bitset<100005> reach[100005]; int find(int x) { return x == par[x] ? x : find(par[x]); } int32_t main() { boost(); cin >> n >> m >> q; for (int i = 1; i <= m; i++) { cin >> u >> v; a[u].push_back(v); r[v].push_back(u); } for (int i = 1; i <= q; i++) { cin >> u >> k; vector<int> vec = {i}; for (int j = 1; j <= k; j++) cin >> v, vec.push_back(v); qs[u].push_back(vec); } for (int i = 1; i <= n; i++) { par[i] = i; dp[i] = 0; nodes[i] = {i}; for (int j : r[i]) { if (dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; nodes[i] = nodes[j]; } else if (dp[j] + 1 == dp[i]) { for (int p : nodes[j]) nodes[i].push_back(p); } } sort(nodes[i].begin(), nodes[i].end()); nodes[i].erase(unique(nodes[i].begin(), nodes[i].end()), nodes[i].end()); for (int j : r[i]) if (dp[j] + 1 == dp[i]) par[j] = i; for (auto qu : qs[i]) { set<int> s; for (int j = 1; j < qu.size(); j++) s.insert(qu[j]); vector<pii > vec; int ret = -1; for (int p : nodes[i]) { if (!s.count(p)) {ret = dp[i]; break;} else vec.push_back({p, dp[i]}); } while (vec.size() && ret == -1) { vector<pii> w; for (pii p : vec) { for (int nxt : a[p.f]) { if (find(nxt) != i) continue; if (!s.count(nxt)) {ret = p.s - 1; break;} else w.push_back({nxt, p.s - 1}); } if (ret != -1) break; } vec = w; } ans[qu[0]] = ret; } } for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]); return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:55:31: 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]
   55 |             for (int j = 1; j < qu.size(); j++) s.insert(qu[j]);
      |                             ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...