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;
namespace
{
} // namespace
void solve()
{
const int SQ = 400000;
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> adj(n), adj_rev(n);
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v, --u, --v;
adj[v].push_back(u);
}
vector<vector<pair<int, int>>> take(n);
for (int i = 0; i < n; i++)
{
take[i].emplace_back(0, i);
for (int j : adj[i])
{
for (auto [l, k] : take[j])
take[i].emplace_back(l + 1, k);
}
sort(take[i].begin(), take[i].end());
take[i].erase(unique(take[i].begin(), take[i].end()), take[i].end());
if ((int)take[i].size() > SQ)
take[i].erase(take[i].begin() + SQ, take[i].end());
}
vector<bool> bad(n);
for (int c = 0; c < q; c++)
{
int u, y;
cin >> u >> y, --u;
vector<int> busy(y);
for (int &v : busy)
cin >> v, --v;
for (int v : busy)
bad[v] = 1;
if (y >= SQ)
{
vector<int> dp(u + 1);
for (int v : busy)
dp[v] = -1;
for (int i = 0; i <= u; i++)
{
for (int j : adj[i])
{
if (dp[j] != -1)
dp[i] = max(dp[i], dp[j] + 1);
}
}
cout << dp[u] << '\n';
}
else
{
int res = -1;
for (auto [l, v] : take[u])
{
if (!bad[v])
res = max(res, l);
}
cout << res << '\n';
}
for (int v : busy)
bad[v] = 0;
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |