#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define ll long long
#define db double
#define ii pair<int,int>
#define pb push_back
#define MASK(i) (1LL << i)
#define sq(i) (1LL * (i) * (i))
#define task "task"
const ll INF = 1e18;
const int inf = 1e9;
const int N = 1e5 + 4;
const int M = 2e5 + 4;
const int S = 316;
int n, m, q;
vector<int> g[N], topo;
vector<ii> lp[N], can[N];
int dp[N];
bool in[N];
void lightset(int t, int y, vector<int> &ban) {
for(int x : ban) in[x] = 1;
for(ii x : lp[t]) {
if(!in[x.se]) {
cout << x.fi << '\n';
for(int tmp : ban) in[tmp] = 0;
return;
}
}
for(int x : ban) in[x] = 0;
cout << -1 << '\n';
}
void heavyset(int t, int y, vector<int> &ban) {
FOR(i, 1, n) dp[i] = 0;
for(int x : ban) dp[x] = -1;
FOR(u, 1, n) {
if(dp[u] == -1) continue;
for(int v : g[u]) dp[v] = max(dp[v], dp[u] + 1);
}
cout << dp[t] << '\n';
}
void solve() {
FOR(i, 1, n) can[i].pb({0, i});
FOR(u, 1, n) {
sort(can[u].begin(), can[u].end(), greater<ii>());
for(ii x : can[u]) {
if(!in[x.se]) {
in[x.se] = 1;
lp[u].pb(x);
}
if(lp[u].size() > S + 1) break;
}
for(ii x : lp[u]) in[x.se] = 0;
for(int v : g[u]) {
for(ii x : lp[u]) {
can[v].pb({x.fi + 1, x.se});
}
}
}
FOR(i, 1, q) {
int t, y;
cin >> t >> y;
vector<int> ban;
FOR(j, 1, y) {
int x;
cin >> x;
ban.pb(x);
}
if(y <= S) lightset(t, y, ban);
else heavyset(t, y, ban);
}
}
signed main() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
while(tc--) {
cin >> n >> m >> q;
FOR(i, 1, m) {
int u, v;
cin >> u >> v;
g[u].pb(v);
}
solve();
}
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |