#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long
#define pb push_back
#define m_pi 2 * acos(0.0)
#define all(a) (a).begin(), (a).end()
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
void solve();
constexpr bool isTc = 0;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
if (isTc)
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
else
solve();
return 0;
}
/*######################################*/
int SQRT;
vector<vector<int>> adj, radj;
int N, M, Q;
void i_merge(vector<pair<int,int>> &S, vector<pair<int,int>> &T)
{
}
void precompute(vector<vector<pair<int,int>>> &pre)
{
for(int i = 0; i <= N; i++)
{
pre[i].push_back({i, 0});
}
for(int i = 1; i <= N; i++)
{
for(auto edge : adj[i])
{
i_merge(pre[i], pre[edge]);
}
}
}
int dp(int node, bitset<100005> &bs)
{
int best = 0;
for(auto i : radj[node])
{
int d = dp(i, bs);
if(d != 0 || !bs[i])
best = max(best, d+1);
}
return best;
}
void solve()
{
cin >> N >> M >> Q;
adj.resize(N+1);
radj.resize(N+1);
for(int i = 0; i < M; i++)
{
int a,b;
cin >> a >> b;
adj[a].emplace_back(b);
radj[b].emplace_back(a);
}
SQRT = sqrt(N);
vector<vector<pair<int,int>>> pre(N+1);
precompute(pre);
bitset<100005> rm;
while(Q--)
{
int T, Y, x;
vector<int> m;
cin >> T >> Y;
m.reserve(Y);
for(int i = 0; i < Y; i++)
{
cin >> x;
rm[x] = 1;
m.push_back(x);
}
int ans;
if(true)
{
ans = dp(T, rm);
}
else
{
}
cout << (ans == 0 && rm[T] ? -1 : ans) << "\n";
for(auto i : m) rm[i] = 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... |