zoukankan      html  css  js  c++  java
  • [SCOI2005]王室联邦

    分块基本没有限制
    所以每次大于等于b就分一块

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    using namespace std;
    typedef long long ll;
    const int _(2e3 + 10);
    
    IL ll Read(){
        char c = '%'; ll x = 0, z = 1;
        for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
        for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
        return x * z;
    }
    
    int b, n, fst[_], num, nxt[_], to[_], cnt, bel[_], S[_], rt[_];
    
    IL void Add(RG int u, RG int v){  to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++;  }
    
    IL void Dfs(RG int u, RG int fa){
        RG int x = S[0];
        for(RG int e = fst[u]; e != -1; e = nxt[e]){
            if(to[e] == fa) continue;
            Dfs(to[e], u);
            if(S[0] - x >= b){
                rt[++num] = u;
                while(S[0] != x) bel[S[S[0]--]] = num;
            }
        }
        S[++S[0]] = u;
    }
    
    int main(RG int argc, RG char *argv[]){
        n = Read(); b = Read(); Fill(fst, -1);
        for(RG int i = 1, u, v; i < n; i++) u = Read(), v = Read(), Add(u, v), Add(v, u);
        if(n < b){  puts("0"); return 0;  }
        Dfs(1, 0);
        while(S[0]) bel[S[S[0]--]] = num;
        printf("%d
    ", num);
        for(RG int i = 1; i <= n; i++) printf("%d ", bel[i]);
        printf("
    ");
        for(RG int i = 1; i <= num; i++) printf("%d ", rt[i]);
        printf("
    ");
        return 0;
    }
    
  • 相关阅读:
    要学习的东西~!~
    Concrete5官网
    PHP免费源码下载
    PHP源码下载1
    PHP源码下载
    PHP框架之ThinkPHP项目CMS内容管理系统源码及开发手册视频
    SELINUX导致数据修改权限不成功
    mysql参数安全设置
    大话存储(1-5)
    存储知识(4)
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8206343.html
Copyright © 2011-2022 走看看