Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int INF=1e9;
- using pii=pair<int,int>;
- vector <int> level[10001],before[100001];
- bool visited[100001],visit[100001];
- int color[100001];
- int t=0;
- bool dfs(int u){
- if(color[u]==1) return true;
- if(color[u]==2) return false;
- color[u]=1;
- t++;
- for(auto v:before[u]){
- if(dfs(v)) return true;
- }
- color[u]=2;
- return false;
- }
- int main(){
- int n,k,T;
- scanf("%d%d%d",&n,&k,&T);
- for(int i=1;i<=n;i++){
- int L,P,q;
- scanf("%d%d",&L,&P);
- level[L].push_back(i);
- for(int j=1;j<=P;j++){
- scanf("%d",&q);
- before[i].push_back(q);
- }
- }
- int i=1,ans=-1;
- bool brk=false;
- for(i=1;i<=k;i++){
- for(auto lv:level[i]){
- if(dfs(lv)){
- brk=true;
- break;
- }
- if(t>T) break;
- }
- if(t>T or brk) break;
- ans=max(ans,i);
- }
- printf("%d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement