Advertisement
YEZAELP

TOI14: Technology

Jun 18th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF=1e9;
  4. using pii=pair<int,int>;
  5. vector <int> level[10001],before[100001];
  6. bool visited[100001],visit[100001];
  7. int color[100001];
  8. int t=0;
  9. bool dfs(int u){
  10.     if(color[u]==1) return true;
  11.     if(color[u]==2) return false;
  12.     color[u]=1;
  13.     t++;
  14.     for(auto v:before[u]){
  15.         if(dfs(v)) return true;
  16.     }
  17.     color[u]=2;
  18.     return false;
  19. }
  20. int main(){
  21.  
  22.     int n,k,T;
  23.     scanf("%d%d%d",&n,&k,&T);
  24.  
  25.     for(int i=1;i<=n;i++){
  26.         int L,P,q;
  27.         scanf("%d%d",&L,&P);
  28.         level[L].push_back(i);
  29.         for(int j=1;j<=P;j++){
  30.             scanf("%d",&q);
  31.             before[i].push_back(q);
  32.         }
  33.     }
  34.  
  35.     int i=1,ans=-1;
  36.     bool brk=false;
  37.     for(i=1;i<=k;i++){
  38.         for(auto lv:level[i]){
  39.             if(dfs(lv)){
  40.                 brk=true;
  41.                 break;
  42.             }
  43.             if(t>T) break;
  44.         }
  45.         if(t>T or brk) break;
  46.         ans=max(ans,i);
  47.     }
  48.  
  49.     printf("%d",ans);
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement