Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C D

时间:2022-09-23 05:53:19

C - Equalize

#include<bits/stdc++.h>
using namespace std;
using namespace std;
string a,b;
int main(){
  int n;
  cin>>n;
  cin>>a>>b;
  ,sum=;
  ;j<n;j++){
     if(a[j]!=b[j]) ans++;
  }
  ;j<n-;j++){
      if(a[j]==b[j]) continue;
     ]==]=='){
        sum++;
        swap(a[j],a[j+]);
     }]==]=='){
        sum++;
        swap(a[j],a[j+]);
     }
  }
  ;j<n;j++){
     if(a[j]!=b[j]) sum++;
  }
  cout<<min(sum,ans)<<endl;

  ;
}

D - Valid BFS?

#include<bits/stdc++.h>
using namespace std;
#define maxn 300005
vector<int>q[maxn];
int de[maxn],fa[maxn],ff[maxn];
int a[maxn],vi[maxn],sz[maxn];
void dfs(int u,int f,int d){
   de[u]=d;
   fa[d]++;
   vi[u]=f;
   ;j<q[u].size();j++){
      int v=q[u][j];
      if(v==f) continue;
      sz[u]++;
      dfs(v,u,d+);
   }
}
int main(){
   memset(de,,sizeof(de));
   memset(fa,,sizeof(fa));
   memset(vi,,sizeof(vi));
   memset(sz,,sizeof(sz));
   memset(ff,,sizeof(ff));
   int n;
   cin>>n;
   ;j<n;j++){
     int u,v;
     cin>>u>>v;
     q[u].push_back(v);
     q[v].push_back(u);
   }
   ;j<=n;j++){
      cin>>a[j];
   }
   dfs(,,);
   ;
   sz[]=;
   ;j<=n;j++){
      int k=de[a[j]];
      )) l++;
      ]!=){
         cout<<"No"<<endl;
         ;
      }
      if(vi[a[j]]!=a[l]){
         cout<<"No"<<endl;
         ;
      }
      if(!ff[a[j]]){
         ff[a[j]]=;
      }else{
        cout<<"No"<<endl;
        ;
      }
      sz[a[l]]--;
      fa[k]--;
   }
   cout<<"Yes"<<endl;
   ;
}