제출 #1124982

#제출 시각아이디문제언어결과실행 시간메모리
1124982alecurseBitaro’s Party (JOI18_bitaro)C++17
14 / 100
129 ms11480 KiB
#include <iostream> #include <vector> using namespace std; int N,M,Q; vector<vector<int> > adj; vector<bool> isin; vector<int> resvis; int trovaris(int x) { if(resvis[x]!=-1) return resvis[x]; int maxres=0; for(auto b : adj[x]) { int th = trovaris(b); if(th==0&&isin[b]) continue; maxres=max(maxres,th+1); } resvis[x]=maxres; return maxres; } int main() { cin>>N>>M>>Q; adj.resize(N+1); resvis.assign(N+1,-1); isin.resize(N+1); for(int i=0;i<M;i++) { int a, b; cin>>a>>b; adj[b].push_back(a); } // for(int i=0;i<Q;i++) { int nodo; cin>>nodo; int sizee; cin>>sizee; for(int i=0;i<sizee;i++) { int th; cin>>th; isin[th]=true; } int risposta = trovaris(nodo); if(risposta==0&&isin[nodo]) { cout<<-1<<"\n"; } else { cout<<risposta<<"\n"; } // cout<<max // } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...