Codeforces Round #720 DIV2 D問題 - Nastia Plays with a Tree

Source

Codeforces Round #720 DIV2 D問題 (2250pt)
Problem description

問題概要

省略

解法

省略

cLayversion 20210524-1)のコード

C++に変換後のコードはこちら

//no-unlocked
int N, A[1d5], B[], deg[];
graph g;
int up[], deled[], ind[];
int ress, res[2][1d5];
unionFind uf;

int sz[1d5], arr[1d5][2];

void dfs(int n, int b){
  up[n] = b;
  deled[n] = 0;
  rep[g.edge[n]](i,g.es[n]) dfs(i,n);
  if(b >= 0 && deg[n] > 2) deg[n]--, deg[b]--, deled[n] = 1;
  rep[g.edge[n]](i,g.es[n]) if(deg[n] > 2 && deled[i]==0) deg[n]--, deg[i]--, deled[i] = 1;
}
{
  REP(rd_int()){
    int i, j, k;
    rd(N,(A--,B--)(N-1));
    g.setEdgeRootedTree(N,N-1,A,B);
    uf.walloc(N, 1);
    ress = 0;
    rep(i,N) deg[i] = 0;
    rep(i,N-1) deg[A[i]]++, deg[B[i]]++;
    dfs(0, -1);

    rep(i,1,N) if(deled[i]) arrInsert(ress, ress, res[0], i, res[1], up[i]);
    rep(i,1,N) if(!deled[i]) uf(i, up[i]);

    k = uf.comp(ind);
    rep(i,k) sz[i] = 0;
    rep(i,N) rep(2-deg[i]) arr[ind[i]][sz[ind[i]]++] = i;

    wt(ress);
    rep(i,ress) wt(res[0][i]+1, res[1][i]+1, arr[i][1]+1, arr[i+1][0]+1);
  }
}

Current time: 2021年12月05日23時51分17秒
Last modified: 2021年05月24日20時55分02秒 (by laycrs)
Tags: Competitive_Programming_Incomplete Codeforces CF720 CF_DIV2_D
トップページに戻る

Logged in as: unknown user (not login)

ログイン: