이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 1e5;
const int INF = (1LL<<61LL)-1;
int n, m, q, dp[MAX_N];
vector<vector<int>> ch;
bool ok[MAX_N];
void long_c(){
for(int i = 0; i<n; i++){
if(ok[i]){
dp[i] = 0;
}
else{
dp[i] = -INF;
}
for(auto e: ch[i]){
dp[i] =max(dp[i], dp[e]+1);
}
}
}
signed main(){
cin>>n>>m>>q;
ch.resize(n);
fill(ok, ok+MAX_N, true);
for(int i = 0; i<m; i++){
int a, b;
cin>>a>>b;
ch[b-1].push_back(a-1);
}
for(int i = 0; i<q; i++){
int t, y;
cin>>t>>y;
t--;
vector<int> rem(y);
for(int i = 0; i<y; i++){
cin>>rem[i];
rem[i]--;
ok[rem[i]] = false;
}
long_c();
cout<<max(dp[t], -1LL)<<endl;
for(auto e: rem){
ok[e] = true;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |