#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
#define fo(i,a,b) for (int i = (a); i <= (b); ++i)
#define fd(i,a,b) for (int i = (a); i >= (b); --i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define maxi(a,b) a=max(a,b)
#define mini(a,b) a=min(a,b)
#define er(x) cerr << #x << " = " << (x) << '\n'
#define siz(x) ((int)(x).size())
#define ve vector
#define _ << ' ' <<
const int N = 2e5+5, inf = 1e9+10, mod = 1e9+7, sq = 200;
int n, m, d[N], deg[N], mxd[N], cnt[N];
ve<int> g[N], rg[N];
ve<ii> res[N];
bool kk[N];
ve<ii> mer(ve<ii> aa, ve<ii> bb) {
ve<ii> cc(siz(aa)+siz(bb));
int pp=0;
for (auto &x:aa) maxi(mxd[x.se],x.fi), cc[pp++]={0,x.se};
for (auto &x:bb) maxi(mxd[x.se],x.fi+1), cc[pp++]={0,x.se};
sort(all(cc)); cc.resize(unique(all(cc))-cc.begin());
fo(i,0,siz(cc)-1) {
cc[i].fi=mxd[cc[i].se];
mxd[cc[i].se]=-1;
}
sort(all(cc),[&](ii x, ii y)->bool{
if (x.fi!=y.fi) return x.fi>y.fi;
return 0;
});
if (siz(cc)>sq) cc.resize(sq);
return cc;
}
ve<int> topo;
void init() {
fo(i,1,n) res[i].pb({0,i});
queue<int> q;
fo(i,1,n) if (deg[i]==0) q.push(i);
while (q.size()) {
int u = q.front(); q.pop(); topo.pb(u);
for (int v:g[u]) {
deg[v]--;
if (deg[v]==0) q.push(v);
}
}
for (int u:topo) {
for (int v:g[u]) {
res[v]=mer(res[v],res[u]);
}
}
}
int brute(int to) {
fo(i,1,n) d[i]=-inf;
d[to]=0;
fd(i,n-1,0) {
int u=topo[i];
for (int v:rg[u]) {
maxi(d[v],d[u]+1);
}
}
int mx=-1;
fo(i,1,n) if (!kk[i]) maxi(mx,d[i]);
return mx;
}
void solve() {
int q;
cin >> n >> m >> q;
fo(i,1,m) {
int u, v; cin >> u >> v;
g[u].pb(v); rg[v].pb(u);
deg[v]++;
}
init();
while (q--) {
int tt, sz; cin >> tt >> sz;
ve<int> busy(sz);
fo(i,0,sz-1) cin >> busy[i], kk[busy[i]]=1;
cout << brute(tt) << '\n';
// if (sz<sq) {
// int mx=-1;
// for (auto &p : res[tt]) {
// if (!kk[p.se]) maxi(mx,p.fi);
// }
// cout << mx << '\n';
// } else {
// cout << brute(tt) << '\n';
// }
fo(i,0,sz-1) kk[busy[i]]=0;
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("a.inp","r")) {
freopen("a.inp","r",stdin);
freopen("a.out","w",stdout);
}
solve();
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | freopen("a.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | freopen("a.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... |