A12954 | BubbleReactor
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are in charge of the BubbleReactor. It consists of $N$ BubbleCores connected with $N$ lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores connected with more than one line of electrical wiring.
Your task is to start the BubbleReactor by starting each BubbleCore. In order for a BubbleCore to be started it needs to be receiving power from a directly connected BubbleCore which is already started. However, you can kick-start one BubbleCore manually without needing power. It is guaranteed that all BubbleCores can be started.
Before the BubbleCore boot up procedure its potential is calculated as the number of BubbleCores it can power on (the number of inactive BubbleCores which are connected to it directly or with any number of inactive BubbleCores in between, itself included)
Start the BubbleReactor so that the sum of all BubbleCores' potentials is maximum.
Your task is to start the BubbleReactor by starting each BubbleCore. In order for a BubbleCore to be started it needs to be receiving power from a directly connected BubbleCore which is already started. However, you can kick-start one BubbleCore manually without needing power. It is guaranteed that all BubbleCores can be started.
Before the BubbleCore boot up procedure its potential is calculated as the number of BubbleCores it can power on (the number of inactive BubbleCores which are connected to it directly or with any number of inactive BubbleCores in between, itself included)
Start the BubbleReactor so that the sum of all BubbleCores' potentials is maximum.
输入格式
First line contains one integer $N (3 \leq N \leq 15.000)$ , the number of BubbleCores.
The following N lines contain two integers $U, V (0 \leq U \neq V < N)$ denoting that there exists electrical wiring between BubbleCores $U$ and $V$ .
The following N lines contain two integers $U, V (0 \leq U \neq V < N)$ denoting that there exists electrical wiring between BubbleCores $U$ and $V$ .
输出格式
Single integer, the maximum sum of all BubbleCores' potentials.
输入输出样例
输入 #1
10 0 1 0 3 0 4 0 9 1 2 2 3 2 7 4 5 4 6 7 8
输出 #1
51
If we start by kickstarting BubbleCup 8 and then turning on cores 7, 2, 1, 3, 0, 9, 4, 5, 6 in that order we get potentials 10 + 9 + 8 + 7 + 6 + 5 + 1 + 3 + 1 + 1 = 51
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted