A841 | Circus--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
The $N$ cows of Farmer John's Circus ($1 \leq N \leq 10^5$) are preparing
their upcoming acts. The acts all take place on a tree with vertices labeled
$1\ldots N$. The "starting state" of an act is defined by a number $1 \leq K
\leq N$ and an assignment of cows $1\dots K$ to the vertices of the tree, so
that no two cows are located at the same vertex.
In an act, the cows make an arbitrarily large number of "moves." In a move, a
single cow moves from her current vertex to an unoccupied adjacent vertex. Two
starting states are said to be equivalent if one may be reached from the other
by some sequence of moves.
For each $1 \leq K \leq N$, help the cows determine the number of equivalence
classes of starting states: that is, the maximum number of starting states
they can pick such that no two are equivalent. Since these numbers may be very
large, output their remainders modulo $10^9 + 7$.
their upcoming acts. The acts all take place on a tree with vertices labeled
$1\ldots N$. The "starting state" of an act is defined by a number $1 \leq K
\leq N$ and an assignment of cows $1\dots K$ to the vertices of the tree, so
that no two cows are located at the same vertex.
In an act, the cows make an arbitrarily large number of "moves." In a move, a
single cow moves from her current vertex to an unoccupied adjacent vertex. Two
starting states are said to be equivalent if one may be reached from the other
by some sequence of moves.
For each $1 \leq K \leq N$, help the cows determine the number of equivalence
classes of starting states: that is, the maximum number of starting states
they can pick such that no two are equivalent. Since these numbers may be very
large, output their remainders modulo $10^9 + 7$.
输入格式
Line $1$ contains $N$.
Lines $2\le i\le N$ each contain two integers $a_i$ and $b_i$ denoting an edge
between $a_i$ and $b_i$ in the tree.
Lines $2\le i\le N$ each contain two integers $a_i$ and $b_i$ denoting an edge
between $a_i$ and $b_i$ in the tree.
输出格式
For each $1\le i\le N,$ the $i$-th line of output should contain the answer
for $K=i$ modulo $10^9+7$.
for $K=i$ modulo $10^9+7$.
输入输出样例
输入 #1
5 1 2 2 3 3 4 3 5
输出 #1
1 1 3 24 120
For $K=1$ and $K=2,$ any two states can be transformed into one another.
Now consider $K=3$, and let $c_i$ denote the location of cow $i$. The state
$(c_1,c_2,c_3)=(1,2,3)$ is equivalent to the states $(1,2,5)$ and $(1,3,2).$
However, it is not equivalent to the state $(2,1,3).$
Now consider $K=3$, and let $c_i$ denote the location of cow $i$. The state
$(c_1,c_2,c_3)=(1,2,3)$ is equivalent to the states $(1,2,5)$ and $(1,3,2).$
However, it is not equivalent to the state $(2,1,3).$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted