题目描述

Everyone knew it would only be a matter of time. So what?

Faced for years on, a peril becomes the every-day reality.

It loses its meaning...

Today the letter of the Bitotian char Bittard to the Byteotian king Byteasar was released to the public.

Bitotia requested annexation of the whole Byteotia on pain of using the Bit Polarizing Magnet (BPM).

If used, the BPM would make each and every road in Byteotia unidirectional.

The enemy knows only too well that this could be a fatal blow to the minimalist Byteotian infrastructure - there is a unique way between each pair of towns.

How badly can the BPM damage the Byteotian infrastructure?

Determine the minimum and the maximum number of such pairs of towns that it will still be possible to travel from one of them to the other while observing the new roads orientation.

给定一颗树,请给树边改成有向边,求连通的点对个数的最大最小值。点对连通,要么a能到达b,要么b能到达a。(n<=250000)

输入输出格式

输入格式:

The first line of the standard input gives a single integer (), the number of towns in Byteotia.

The lines that follow describe these roads.

Each such line holds two integers, and (), which indicate that there is a direct road (still bidirectional at the moment) linking the towns no. and .

In tests worth 60% of the total points, the additional constraint holds;moreover, in some of those, worth 30% of the total points, it even holds that .

输出格式:

Two integers should be printed to the first and only line of the standard output.

The first number should be the minimum and the second - the maximum number of pairs of towns which could remain connected (though in one direction only) after the roads are polarized.

输入输出样例

输入样例#1:

4

1 2

1 3

1 4

输出样例#1:

3 5

说明

给定一颗树,请给树边改成有向边,求连通的点对个数的最大最小值。点对连通,要么a能到达b,要么b能到达a。(n<=250000)


神奇的一道题反正我不会

首先考虑最小值

因为每连出去一条边至少会形成一个点对

所以我们就考虑最小的情况

因为是一颗树

所以只有n-1条边,答案就是n-1

具体连法就是第i-1层向第i层连的边与第i层向第i+1层的连的边的方向相反

然后考虑最大值怎么求反正我不会证明

最大值就是找打树的重心

然后每个子树内部连边方向要相同

然后尽量使得连向root的边的子树大小之和和root向外连出的边的子树大小之和相差小

就感性理解一下反正我也不会证明

然后把每个子树按照大小二进制拆分一下

之后做一个背包就行了

#include<queue>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
# define LL long long
const int M = 250005 ;
const int INF = 2147483647 ;
using namespace std ;
inline int read() {
char c = getchar() ; int x = 0 , w = 1 ;
while(c>'9'||c<'0') { if(c=='-') w = -1 ; c = getchar() ; }
while(c>='0'&&c<='9') { x = x*10+c-'0' ; c = getchar() ; }
return x*w ;
} int n , m ;
struct E { int Nxt , to ; }edge[M<<1];
int hea[M] , num ;
inline void add_edge(int from , int to) {
edge[++num].Nxt = hea[from] ; edge[num].to = to ; hea[from] = num ;
}
int size[M] , tmax , root , dep[M] , w[M<<1] ;
LL Ans = 0 ;
bitset< M > f ;
void Getroot(int u , int father) {
size[u] = 1 ; int Maxson = 0 ;
for(int i = hea[u] ; i ; i = edge[i].Nxt) {
int v = edge[i].to ;
if(v == father) continue ;
Getroot(v , u) ;
size[u] += size[v] ;
Maxson = max(Maxson , size[v]) ;
}
Maxson = max(Maxson , n - size[u]) ;
if(Maxson < tmax)
tmax = Maxson , root = u ;
}
int main() {
n = read() ;
for(int i = 1 , u , v ; i < n ; i ++) {
u = read() , v = read() ;
add_edge(u , v) ; add_edge(v , u) ;
}
tmax = n ;
Getroot(1 , 0) ;
Getroot(root , root) ;
for(int i = 1 ; i <= n ; i ++) Ans += size[i] - 1 ;
for(int i = hea[root] ; i ; i = edge[i].Nxt) {
int v = edge[i].to ;
++w[size[v]] ;
}
for(int i = 1 ; i <= n ; i ++)
while(w[i] > 2)
w[i] -= 2 , ++w[i<<1] ;
f[0] = 1 ;
for(int i = 1 ; i <= n ; i ++)
while(w[i] -- )
f |= f << i ;
int x ;
for(x = (n >> 1) ; !f[x] ; -- x) ;
printf("%d %lld\n",n - 1 , Ans + 1LL * x * (n - 1 - x)) ;
return 0 ;
}

[POI2013]POL-Polarization的更多相关文章

  1. 【BZOJ3425】Poi2013 Polarization 猜结论+DP

    [BZOJ3425]Poi2013 Polarization Description 给定一棵树,可以对每条边定向成一个有向图,这张有向图的可达点对数为树上有路径从u到达v的点对(u,v)个数.求最小 ...

  2. BZOJ3425 : Poi2013 Polarization

    最小值肯定是把树看作二分图,此时答案为$n-1$. 最大值一定是选取重心为根,任意一个子树要么全部指向根,要么全部背离根,这样可以制造最大的星型图. 统计出每个子树的大小后做01背包,如果小于$\sq ...

  3. BZOJ3425[POI2013]Polarization——DP+bitset+分块

    题目描述 Everyone knew it would only be a matter of time. So what? Faced for years on, a peril becomes t ...

  4. BZOJ.3425.[POI2013]Polarization(DP 多重背包 二进制优化)

    BZOJ 洛谷 最小可到达点对数自然是把一条路径上的边不断反向,也就是黑白染色后都由黑点指向白点.这样答案就是\(n-1\). 最大可到达点对数,容易想到找一个点\(a\),然后将其子树分为两部分\( ...

  5. POI2013题解

    POI2013题解 只做了BZ上有的\(13\)道题. 就这样还扔了两道神仙构造和一道计算几何题.所以只剩下十道题了. [BZOJ3414][Poi2013]Inspector 肯定是先二分答案,然后 ...

  6. [POI2013]Łuk triumfalny

    [POI2013]Łuk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选 ...

  7. [POI2013]Polaryzacja

    [POI2013]Polaryzacja 题目大意: 给定一棵\(n(n\le250000)\)个点的树,可以对每条边定向成一个有向图,这张有向图的可达点对数为树上有路径从\(u\)到达\(v\)的点 ...

  8. [POI2013]Taksówki

    [POI2013]Taksówki 题目大意: ABC三地在同一条直线上,AC相距\(m(m\le10^{18})\)米,AB相距\(d\),B在AC之间.总共有\(n(n\le5\times10^5 ...

  9. [POI2013]Usuwanka

    [POI2013]Usuwanka 题目大意: 一排\(n\)个球,有黑白两种颜色.每取走一个球会在原位置放一个水晶球.求构造一种取球方案,满足: 每次取走\(k\)个白球和\(1\)个黑球: 一次取 ...

  10. [POI2013]Morskie opowieści

    [POI2013]Morskie opowieści 题目大意: 一个\(n(n\le5000)\)点\(m(m\le5000)\)边无向图,边权均为\(1\),有\(k(k\le10^6)\)个询问 ...

随机推荐

  1. VIM使用技巧15

    在vim的插入模式下,有时需要插入寄存器中的文本: 1.使用<C-r>{register} 2.使用<C-r><C-p>{register} 3.使用<C-r ...

  2. Linux下汇编语言学习笔记43 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  3. C#高级编程第9版 第一章 .NET体系结构 读后笔记

    .NET的CLR把源代码编译为IL,然后又把IL编译为平台专用代码. IL总是即时编译的,这一点的理解上虽然明白.当用户操作C#开发的软件时,应该是操作已经编译好的程序.那么此时安装在客户机上的程序是 ...

  4. 权限框架之Shiro详解(非原创)

    文章大纲 一.权限框架介绍二.Shiro基础介绍三.Spring Boot整合Shiro代码实战四.项目源码与资料下载五.参考文章   一.权限框架介绍 1. 什么是权限管理   权限管理属于系统安全 ...

  5. 得到java异常printStackTrace的详细信息

    平时写Java代码时,想看抛出的异常信息,来找出具体的异常点,我们常常会用Exception.toString ()或者 Exception.getMessage()来取得异常信息,再把它print到 ...

  6. python dos2unix

    有时你在windows上创建的文件拿到Linux/unix上运行会出错, 这是因为windows上有些字符如换行符在linux/unix不识别.这种情况下需要用dos2unix这个工具把文件转换成li ...

  7. 学习swift从青铜到王者之字符串和运算符02

    1 字符和字符串初步  var c :Character = "a" 2 构造字符串  let str1 = "hello" let str2 = " ...

  8. HDOJ 4259 Double Dealing

    找每一位的循环节.求lcm Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. C# .NET using ManagementObjectSearcher提示缺少引用怎么办

    在下图中,即使引用了System.Management还是会出现报错   其实只要添加这条引用就可以了

  10. 安卓数据传递之---putextra与putextras

    一.public Intent putExtra (String name, double[] value) 设置方法 intent.putExtra("aaa", "b ...