Advertisement
ec1117

Untitled

Feb 20th, 2022
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. #define f first
  6. #define s second
  7.  
  8. int n,t;
  9. char cur[105];
  10. bool posK[255], posI[105];
  11. vector<pair<int,pair<int,int>>> v;
  12.  
  13.  
  14. bool possible(int p0, int k){
  15.     vector<bool> infected(n,false);
  16.     vector<int> count(n,0);
  17.     infected[p0]=true;
  18.     for(auto& x:v){
  19.         int X=x.s.f, Y=x.s.s;
  20.         if(infected[X])count[X]++;
  21.         if(infected[Y])count[Y]++;
  22.         if(infected[X] && count[X]<=k) infected[Y]=true;
  23.         if(infected[Y] && count[Y]<=k) infected[X]=true;
  24.     }
  25.     for(int i=0;i<n;i++){
  26.         if(infected[i] && cur[i]=='0')return false;
  27.         if(!infected[i] && cur[i]=='1')return false;
  28.     }
  29.     return true;
  30. }
  31.  
  32. int main(){
  33.     cin>>n>>t;
  34.     for(int i=0;i<n;i++){
  35.         cin>>cur[i];
  36.     }
  37.     for(int i=0;i<t;i++){
  38.         int a,b,c;cin>>a>>b>>c;
  39.         b--;c--;//we are indexing at 0
  40.         v.push_back({a,{b,c}});
  41.     }
  42.     sort(v.begin(),v.end());
  43.  
  44.     for(int i=0;i<n;i++){
  45.         for(int k=0;k<=251;k++){
  46.             if(possible(i,k)){
  47.                 posK[k]=true;
  48.                 posI[i]=true;
  49.             }
  50.         }
  51.     }
  52.  
  53.     int ans=0,lower=251,higher=0;
  54.     for(int i=0;i<=251;i++) if(posK[i]) higher=i;
  55.     for(int i=251;i>=0;i--) if(posK[i]) lower=i;
  56.     for(int i=0;i<n;i++)if(posI[i])ans++;
  57.     cout<<ans<<" "<<lower<<" ";
  58.     if(higher==251)cout<<"Infinity";
  59.     else cout<<higher;
  60.     cout<<endl;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement