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;
void maxi(int &x, int y) {
if(x < y) x = y;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
const int C = 300;
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> g(n+1);
vector<vector<int>> r(n+1);
for(int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
g[u].push_back(v);
r[v].push_back(u);
}
vector<int> dst(n+1);
vector<vector<pair<int, int>>> list(n+1);
for(int i = 1; i <= n; ++i) {
for(int x : r[i]) {
for(auto p : list[x]) maxi(dst[p.second], p.first);
}
for(int x : r[i]) {
for(auto p : list[x]) {
if(dst[p.second] == p.first) {
list[i].push_back({p.first+1, p.second});
dst[p.second] = -1;
}
}
}
list[i].push_back({0, i});
sort(list[i].rbegin(), list[i].rend());
while((int)list[i].size() > C) list[i].pop_back();
for(int x : r[i]) {
for(auto p : list[x]) dst[p.second] = 0;
}
}
vector<bool> blocked(n+1);
while(q--) {
int t, x; cin >> t >> x;
vector<int> v(x);
for(int i = 0; i < x; ++i) {
cin >> v[i];
blocked[v[i]] = 1;
}
if(x < C) {
for(pair<int, int> p : list[t]) {
if(!blocked[p.second]) {
cout << p.first << '\n';
break;
}
}
} else {
vector<int> dp(n+1, -1e6);
for(int i = 1; i <= t; ++i) {
if(!blocked[i]) {
dp[i] = 0;
}
for(int x : r[i]) {
maxi(dp[i], dp[x]+1);
}
}
cout << dp[t] << '\n';
}
for(int i : v) blocked[i] = 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... |