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;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,1:0; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,1:0; }
const int N=1e5;
int n,m,q,dp[N],rm[N];
bool bad[N];
vector<int> adj[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int s,e;m--;) {
cin >> s >> e;
adj[--s].push_back(--e);
}
for (int t,f;q--;) {
cin >> t >> f;
--t;
for (int i=0;i<f;i++) {
cin >> rm[i];
bad[--rm[i]]=true;
}
int res=-1;
dp[t]=0;
if (!bad[t]) {
res=0;
}
for (int i=t-1;i>=0;--i) {
dp[i]=-(1<<30);
for (int &j:adj[i]) {
if (j<=t) {
cmax(dp[i],1+dp[j]);
}
}
if (!bad[i]) {
cmax(res,dp[i]);
}
}
cout << res << "\n";
for (int i=0;i<f;i++) {
bad[rm[i]]=false;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |