Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define f first
- #define s second
- int n,t;
- char cur[105];
- bool posK[255], posI[105];
- vector<pair<int,pair<int,int>>> v;
- bool possible(int p0, int k){
- vector<bool> infected(n,false);
- vector<int> count(n,0);
- infected[p0]=true;
- for(auto& x:v){
- int X=x.s.f, Y=x.s.s;
- if(infected[X])count[X]++;
- if(infected[Y])count[Y]++;
- if(infected[X] && count[X]<=k) infected[Y]=true;
- if(infected[Y] && count[Y]<=k) infected[X]=true;
- }
- for(int i=0;i<n;i++){
- if(infected[i] && cur[i]=='0')return false;
- if(!infected[i] && cur[i]=='1')return false;
- }
- return true;
- }
- int main(){
- cin>>n>>t;
- for(int i=0;i<n;i++){
- cin>>cur[i];
- }
- for(int i=0;i<t;i++){
- int a,b,c;cin>>a>>b>>c;
- b--;c--;//we are indexing at 0
- v.push_back({a,{b,c}});
- }
- sort(v.begin(),v.end());
- for(int i=0;i<n;i++){
- for(int k=0;k<=251;k++){
- if(possible(i,k)){
- posK[k]=true;
- posI[i]=true;
- }
- }
- }
- int ans=0,lower=251,higher=0;
- for(int i=0;i<=251;i++) if(posK[i]) higher=i;
- for(int i=251;i>=0;i--) if(posK[i]) lower=i;
- for(int i=0;i<n;i++)if(posI[i])ans++;
- cout<<ans<<" "<<lower<<" ";
- if(higher==251)cout<<"Infinity";
- else cout<<higher;
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement