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;
int N, M, Q;
vector<pair<int, int>> Canals;
vector<vector<int>> adj;
vector<int> T, Y;
vector<vector<int>> C;
vector<vector<int>> dp;
void dfs(int x){
dp[x][x]=0;
for(auto u : adj[x]){
dfs(u);
dp[x][u]= max(dp[x][u], 1);
for(int i = x+1; i < N; i++){
if(dp[u][i]==-1)continue;
dp[x][i] = max(dp[x][i], dp[u][i]+1);
}
}
}
signed main(){
cin >> N >> M >> Q;
Canals.resize(M);
adj.resize(N);
dp.resize(N, vector<int>(N, -1));
for(int i = 0; i < M; i++){
cin >> Canals[i].first >> Canals[i].second;
Canals[i].first--; Canals[i].second--;
adj[Canals[i].first].push_back(Canals[i].second);
}
dfs(0);
/*for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
cout << i << " -> " << j << " = " << dp[i][j] << "\n";
}
}*/
T.resize(Q);
Y.resize(Q);
C.resize(Q);
vector<int> TooBusy(N, false);
for(int i = 0; i < Q; i++){
fill(TooBusy.begin(), TooBusy.end(), false);
cin >> T[i] >> Y[i];
T[i]--;
C[i].resize(Y[i]);
for(int j = 0; j < Y[i]; j++){
cin >> C[i][j];
C[i][j]--;
TooBusy[C[i][j]]=true;
}
int ans = -1;
for(int j = 0; j < N; j++){
//cout << i << " && " << T[i] << "\n";
if(TooBusy[j])continue;
ans = max(ans, dp[j][T[i]]);
}
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |