#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define sep ' '
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define kill(x) {cout << x << endl;return;}
#define sz(x) int(x.size())
#define SP(x) setprecision(x)
#define mod(x) (1ll*x%M+M)%M
#define pq priority_queue
#define mid (l+r)/2
// #define mid2 (l+r+1)/2
#define pll pair<ll, ll>
#define REP(i, k) for (int i = 0 ; i < k ; i ++)
#define MP make_pair
#define us unordered_set
const int M = 998244353;
const int N = 1e5+10;
const int B = 200;
int n, m, q;
vi adj[N], rev_adj[N];
int dp[N];
vector<pii> far[N];
// {dist, vertex}
bool vis[N];
bool cmp(pii &a, pii &b) {
return a.F > b.F;
}
void f(int t, int y) { // BIG y
vi c(y);
bitset<N> ban;
for(int i = 0 ; i < y ; i ++)
cin >> c[i], ban[--c[i]] = true;
fill(dp, dp+n, -1);
dp[t] = 0;
int ans = (ban[t] ? -1 : 0);
for(int i = t-1 ; i >= 0 ; i --) {
for(int j: rev_adj[i]) {
if (dp[j] != -1) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
if (!ban[i])
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
void g(int t, int y) { // SMALL y
vi c(y);
bitset<N> ban;
for(int i = 0 ; i < y ; i ++)
cin >> c[i], ban[--c[i]] = true;
int ans = -1;
for(auto [d, i]: far[t]) {
if (!ban[i]) {
ans = max(ans, d);
}
}
cout << ans << endl;
}
void solve() {
cin >> n >> m >> q;
for(int i = 0 ; i < m ; i ++) {
int u, v; cin >> u >> v; u--, v--; adj[v].pb(u), rev_adj[u].pb(v);
}
REP(i, n) {
vector<pii> tmp;
for(int neigh: adj[i]) {
for(auto [d, j]: far[neigh]) {
tmp.pb({d+1, j});
}
}
tmp.pb(make_pair(0, i));
sort(tmp.begin(), tmp.end(), cmp);
for(int i = 0 ; i < tmp.size(); i ++)
vis[tmp[i].S] = false;
REP(j, tmp.size()) {
if (!vis[tmp[j].S]) {
vis[tmp[j].S] = true;
far[i].pb(tmp[j]);
}
}
if (far[i].size() > B)
far[i].resize(B);
}
while(q--) {
int t, y; cin >> t >> y; t--;
if (y >= B) {
f(t, y);
} else {
g(t, y);
}
}
}
// check MAXN
int32_t main() {
fastIO;
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |