This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
const int N = 1e5 + 7, K = 50;
int n, m, q;
vector <int> g[N];
vector <ii> dp[N];
bool del[N];
int get1(int u) {
for (auto e : dp[u]) if (!del[e.second]) return e.first;
return -1;
}
int mx[N];
int get2(int u) {
for (int i = 1; i <= u; ++i) {
if (del[i]) mx[i] = -N;
else mx[i] = 0;
for (int v : g[i]) mx[i] = max(mx[i], mx[v] + 1);
}
return max(-1, mx[u]);
}
bool comp(ii a, ii b) { return a.second < b.second || (a.second == b.second && a.first > b.first); }
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v; g[v].app(u);
}
for (int i = 1; i <= n; ++i) {
dp[i].app({0, i});
for (int v : g[i]) for (auto e : dp[v]) dp[i].app({e.first + 1, e.second});
sort(all(dp[i]), comp);
vector <ii> tmp;
for (int j = 0; j < dp[i].size(); ++j) if (j == 0 || dp[i][j].second != dp[i][j - 1].second) tmp.app(dp[i][j]);
dp[i] = tmp;
sort(all(dp[i])); reverse(all(dp[i]));
while (dp[i].size() > K) dp[i].pop_back();
}
while (q--) {
int u, k;
cin >> u >> k;
vector <int> a(k);
for (int i = 0; i < k; ++i) cin >> a[i];
for (int e : a) del[e] = 1;
if (k < K) cout << get1(u) << '\n';
else cout << get2(u) << '\n';
for (int e : a) del[e] = 0;
}
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:42:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < dp[i].size(); ++j) if (j == 0 || dp[i][j].second != dp[i][j - 1].second) tmp.app(dp[i][j]);
~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |