이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
vector<int> graph[maxn+5];
int block[maxn+5], dp[maxn+5];
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, Q;
cin >> n >> m >> Q;
for(int i=0; i<m; i++) {
int a, b;
cin >> a >> b;
graph[b].push_back(a);
}
while(Q--) {
int T, Y;
cin >> T >> Y;
for(int i=0; i<Y; i++) {
int x;
cin >> x;
block[x] = 1;
}
for(int i=1; i<=n; i++) dp[i] = -1e9;
dp[T] = 0;
for(int i=n; i>=1; i--)
for(int &j : graph[i]) dp[j] = max(dp[j], dp[i] + 1);
int mx = -1;
for(int i=1; i<=n; i++) if(!block[i]) mx = max(mx, dp[i]);
cout << mx << '\n';
for(int i=1; i<=n; i++) block[i] = 0;
}
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... |