#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define double long double
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
const int N = 1000002;
//const int inf = 1e18;
//const int mx = 1e13;
//const int mod = 1e9 + 7;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
void solve(){
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> g(n+1), ig(n+1);
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
g[u].pb(v);
ig[v].pb(u);
}
vector<map<int,int>> mp(n+1);
for(int i = 1; i <= n; i++){
for(auto to:ig[i]){
for(auto [a, cnt] : mp[to]){
chmax(mp[i][a], cnt+1);
}
}
mp[i][i] = 0;
vector<array<int,2>> v;
for(auto [a, cnt] : mp[i])v.pb({a, cnt});
sort(rall(v));
mp[i].clear();
for(int x = 0; x < min((int)v.size(), 100ll); x++)mp[i][v[x][0]] = v[x][1];
}
//for(int i = 1; i <= n; i++){
//cout << i << '\n';
//for(auto [a, cn]:mp)
//}
while(q--){
int x;
cin >> x;
int nm;cin >> nm;
set<int> st;
for(int i = 0; i < nm; i++){
int v;
cin >> v;
st.insert(v);
}
int ans = -1;
//if(nm >= 100){
vector<int> dp(x + 1, -n);
dp[x] = 0;
for(int i = x; i > 0; i--){
for(auto to : ig[i])
chmax(dp[to], dp[i] + 1);
}
for(int i = 1; i <= x; i++)
if(!st.count(i))chmax(ans, dp[i]);
//}else{
//for(auto [a,cn]:mp[x])
//if(!st.count(a))
//chmax(ans, cn);
//}
cout << ans << '\n';
};
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
};
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |