#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 = 1e5 + 15;
const int block_sz = 350;
int n, m, q;
vector<int> g[MAX];
vector<pii> dp[MAX];
bool busy[MAX];
int f[MAX];
bool opt[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
}
auto combine = [&](vector<pii>& a, vector<pii>& b) -> vector<pii>{
vector<pii> c;
int i = 0, j = 0;
while(i < sz(a) || j < sz(b)){
if(sz(c) == block_sz) break;
if(i == sz(a)){
if(!opt[b[j].se]){
opt[b[j].se] = true;
c.push_back(b[j]);
c.back().fi++;
}
j++;
continue;
}
if(j == sz(b)){
if(!opt[a[i].se]){
opt[a[i].se] = true;
c.push_back(a[i]);
}
i++;
continue;
}
if(a[i].fi > b[j].fi){
if(!opt[a[i].se]){
opt[a[i].se] = true;
c.push_back(a[i]);
}
i++;
}
else{
if(!opt[b[j].se]){
opt[b[j].se] = true;
c.push_back(b[j]);
c.back().fi++;
}
j++;
}
}
for(auto e : c) opt[e.se] = false;
return c;
};
for(int u = 1; u <= n; u++){
for(int v : g[u]){
dp[u] = combine(dp[u], dp[v]);
}
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){
bool ok = false;
for(auto &[k, node] : dp[u]){
if(!busy[node]){
ok = true;
cout << k << endl;
break;
}
}
if(!ok) cout << -1 << endl;
}
else{
fill(f + 1, f + 1 + n, 0);
int ans = 0;
f[u]++;//push idx +1
for(int i = u; i >= 1; i--){
if(!f[i]) continue;
if(!busy[i]) maximize(ans, f[i]);
for(int j : g[i]) maximize(f[j], f[i] + 1);
}
ans--;
cout << ans << 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();
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int main()':
bitaro.cpp:138:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
138 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:139:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
139 | 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... |