#include<bits/stdc++.h>
using namespace std;
#define debug(...) 40
using ll = long long;
using pii = pair<int,int>;
// #define int long long
#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T1, class T2>bool chmax(T1 &a, T2 b){return a < b ? a = b, 1 : 0;}
template <class T1, class T2>bool chmin(T1 &a, T2 b){return a > b ? a = b, 1 : 0;}
void setIO(string s) {
// freopen((s + ".inp").c_str(), "r", stdin);
// freopen((s + ".out").c_str(), "w", stdout);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int maxn = 2e5 + 5;
const int mod = 998244353;
const ll inf = 1e18;
vector<int> ad[maxn], cur;
vector<array<int, 2>> node[maxn];
int dis[maxn], vis[maxn], bad[maxn], dp[maxn];
int32_t main() {
// setIO("262144");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
REP(i, m){
int u, v;
cin >> u >> v;
ad[v].pb(u);
}
const int block = 100;
for (int i = 1; i <= n; i++, cur.clear()){
for (auto j : ad[i]){
for (auto [w, u] : node[j]){
if (vis[u] == i) chmax(dis[u], w + 1);
else vis[u] = i, dis[u] = w + 1, cur.pb(u);
}
}
for (auto u : cur) node[i].pb({dis[u], u});
node[i].pb({0, i});
sort(node[i].rbegin(), node[i].rend());
while(node[i].size() > block) node[i].pop_back();
}
FOR(cnt, 1, q){
int t, k, x, ans = -1;
cin >> t >> k;
REP(i, k){
int x;
cin >> x;
bad[x] = cnt;
}
if (k < block){
for (auto [w, u] : node[t]){
if (bad[u] != cnt){
ans = w;
break;
}
}
}
else{
fill(dp, dp + n + 1, -1);
for (int i = 1; i <= t; i++){
if (bad[i] != cnt) dp[i] = 0;
for (auto j : ad[i]){
if (dp[j] != -1) chmax(dp[i], dp[j] + 1);
}
}
ans = dp[t];
}
cout << ans << "\n";
}
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'void setIO(std::string)':
bitaro.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((s+".out").c_str(),"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... |