#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>
using namespace std;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int MAX = 2e5 + 15;
const int block_sz = 550;
int n, m, q;
vector<int> g[MAX];
vector<pii> dp[MAX];
bool busy[MAX];
int f[MAX];
void solve(){
cin >> n >> m >> q;
for(int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
g[v].push_back(u); //reverse edge
}
for(int u = 1; u <= n; u++){
map<int, int> mp;
for(int v : g[u]){
for(auto &[k, node] : dp[v]) maximize(mp[node], k+1);
}
for(auto e : mp) dp[u].push_back({e.se, e.fi});
sort(all(dp[u]), greater<pii>());
while(sz(dp[u]) > block_sz) dp[u].pop_back();
dp[u].push_back({0, u});
}
while(q--){
int u, num; cin >> u >> num;
vector<int> ban;
while(num--){
int x; cin >> x;
ban.push_back(x);
busy[x] = true;
}
if(sz(ban) < block_sz){
for(auto &[k, node] : dp[u]){
if(!busy[node]){
cout << k << endl;
break;
}
}
}
else{
fill(f + 1, f + 1 + n, 0);
for(int i = 1; i <= u; i++){
for(int j : g[i]) if(!busy[j] || f[j]){
maximize(f[i], f[j] + 1);
}
}
cout << f[u] << endl;
}
for(int x : ban) busy[x] = false;
}
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | 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... |