题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

Posted dreagonm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)相关的知识,希望对你有一定的参考价值。

还是dfs?

好像自己写的有锅

过不去

看了题解修改了才过qwq

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <set>
using namespace std;
int u[200010],v[200010],n,m,k,ans;
bool isdel[200010],vis[200010];
set<int> sons[200010];
stack<int> S;
void dfs(int u){
  if(sons[u].size()>=k)
    return;
  if(vis[u])
    return;
  vis[u]=true;
  ans--;
  for(auto i=sons[u].begin();i!=sons[u].end();i++){
        sons[*i].erase(u);
        dfs(*i);
  }
  sons[u].clear();
}
int main(){
  scanf("%d %d %d",&n,&m,&k);
  for(int i=1;i<=m;i++){
    scanf("%d %d",&u[i],&v[i]);
    sons[u[i]].insert(v[i]);
    sons[v[i]].insert(u[i]);
  }
  ans=n;
  for(int i=1;i<=n;i++)
      dfs(i);
    if(ans>=k){
      S.push(ans);
      }
    else
      S.push(0);
  for(int i=m;i>=2;i--){
    sons[u[i]].erase(v[i]);
    sons[v[i]].erase(u[i]);
    dfs(u[i]);
    dfs(v[i]);
    if(ans>=k){
      S.push(ans);
    }
    else
      S.push(0);
  }
  while (!S.empty()) {
    printf("%d
",S.top());
    S.pop();
  }
  return 0;
}

 

以上是关于题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)的主要内容,如果未能解决你的问题,请参考以下文章

Manthan Codefest 19 题解

Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)

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

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

Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造

Manthan, Codefest 16(G. Yash And Trees(dfs序+线段树))