This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
const int B = 315;
vector<int> adj[MAXN], rev[MAXN];
int dist[MAXN];
bool notok[MAXN];
vector<pair<int, int>> f[MAXN];
struct cmp {
bool operator()(const int& x, const int& y) {
return dist[x] > dist[y];
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, m, q;
cin>>n>>m>>q;
for(int i= 0;i<m;i++){
int u, v;
cin>>u>>v;
adj[u].pb(v);
rev[v].pb(u);
}
clr(dist, 0);
for(int i=1;i<=n;i++){
set<int, cmp> s;
s.insert(i);
for(int v: rev[i]){
for(auto it: f[v]){
dist[it.sc] = max(it.fr+1, dist[it.sc]);
s.insert(it.sc);
}
}
int curr = 0;
for(int u: s){
if(curr >= B){
break;
}
f[i].pb({dist[u], u});
curr++;
}
for(auto it: s){
dist[it] = 0;
}
// dbg(i);
// for(auto it: f[i]){
// cout<<it.fr<<' '<<it.sc<<endl;
// }
// printvector(s);
}
clr(notok, 0);
while(q--){
int x, y; cin>>x>>y;
vector<int> v;
for(int i= 0;i<y;i++){
int t1; cin>>t1;
v.pb(t1);
notok[t1] =1;
}
if(y >= B){
int dp[n+2], ans = -1;
for(int i=1;i<=n;i++) dp[i] = -INF;
dp[x] = 0;
for(int i= x;i>=1;i--){
for(int v: adj[i]){
dp[i] = max(dp[v]+1, dp[i]);
}
if(notok[i]) continue;
ans = max(ans, dp[i]);
}
cout<<ans<<endl;
} else {
int ans = -1;
for(auto &[d, u]: f[x]){
if(notok[u]) continue;
ans = d;
break;
}
cout<<ans<<endl;
}
for(int i: v){
notok[i] = 0;
}
}
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:97:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
97 | for(auto &[d, u]: f[x]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |