D:类似于noip2018d1t3,子树内的链应该贪心的尽量合并而不是拆开。则设f[i]为i子树内满足选的链尽量多的情况下根所在的链的最长长度即可。于是可以线性对某个k求得答案。

  注意到长度为k的链不多于n/k个。类似于整除分块可以得到答案不同的k只有O(√n)种。于是我们每做一次dp,可以二分一下该答案的k的上界,就能做到O(n√nlogn)了。卡不来常。

  本来一直在考虑的是所有答案总和不超过nlogn,想了一年也不太会,结果好像确实可以用这个性质做到O(nlog2n)?先不管了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,p[N],t,f[N],ans[N];
struct data{int to,nxt;
}edge[N<<1];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
int calc(int k,int from,int x)
{
int s=0;
for (int i=p[k];i;i=edge[i].nxt)
if (edge[i].to!=from) s+=calc(edge[i].to,k,x);
int mx=0,mx2=0;
for (int i=p[k];i;i=edge[i].nxt)
if (edge[i].to!=from)
if (f[edge[i].to]>mx) mx2=mx,mx=f[edge[i].to];
else mx2=max(mx2,f[edge[i].to]);
if (mx+mx2+1>=x) s++,f[k]=0;
else f[k]=mx+1;
return s;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<n;i++)
{
int x=read(),y=read();
addedge(x,y),addedge(y,x);
}
for (int i=1;i<=n;i++)
{
ans[i]=calc(1,1,i);
int l=i+1,r=n,u=i;
while (l<=r)
{
int mid=l+r>>1;
if (calc(1,1,mid)!=ans[i]) r=mid-1;
else l=mid+1,u=mid;
}
for (int j=i+1;j<=u;j++) ans[j]=ans[i];
i=u;
}
for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
return 0;
//NOTICE LONG LONG!!!!!
}

  E:咕咕咕

Codeforces Round #507 Div. 1的更多相关文章

  1. Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937

    https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...

  2. Codeforces Round #507 (Div. 2)C(贪心,逆向遍历,构造)

    #include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];i ...

  3. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...

  4. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. RNG牛掰!

    2018-05-21 RNG牛掰!Uzi圆梦! 不说了,先去哭了! 2018-07-08 洲际赛后更新,RNG依然牛逼! 2018-08-30 亚运后后更新,UZI加油! 2018-10-22 继续加 ...

  2. 网络拓扑自动发掘之三层设备惯用的SNMP OID的含义

    原文地址:https://blog.csdn.net/maty_wang/article/details/81305070 1. ipNetToMediaIfIndex Name/OID: ipNet ...

  3. c++入门之——const在函数名前面和函数后面的区别

    class Test(){ public: Test(){} const int foo(int a); const int foo(int a) const; }; 一.概念 当const在函数名前 ...

  4. pycharm异常问题之Unable to save settings: Failed to save settings. Please restart PyCharm

    pycharm异常之Unable to save settings: Failed to save settings. Please restart PyCharm 今天一不小心将电脑关了,但是关机之 ...

  5. rest-framework的认证组件

    认证组件 1.登录认证(与组件无关): 首先要在model表内添加用户表和token表: from django.db import models # Create your models here. ...

  6. 06_Hadoop分布式文件系统HDFS架构讲解

    mr  计算框架 假如有三台机器 统领者master 01  02  03  每台机器都有过滤的应用程序 移动数据 01机== 300M  >mr 移动计算  java程序传递给各个机器(mr) ...

  7. 安装使用swoole

    swoole首页:https://www.swoole.com/ 方法1:使用pecl安装 pecl install swoole 注意,php版本必须是7.0以及7.0以上的版本. 方法2:编译源码 ...

  8. 通过爬虫程序深入浅出java 主从工作模型

    随手做的爬虫程序在   https://github.com/rli07/master_java/blob/master/spider.zip  可下载. 这是我做的系统学习图, 可以参考一下 系统架 ...

  9. Java 里如何实现线程间通信(转载)

    出处:http://www.importnew.com/26850.html 正常情况下,每个子线程完成各自的任务就可以结束了.不过有的时候,我们希望多个线程协同工作来完成某个任务,这时就涉及到了线程 ...

  10. 字符串和ASCII之间的转换

    public class CharToAscii { public static void main(String[] args) { CharToAscii.AscToString(); CharT ...